JS Arrays to Object

Create a JS object from the two arrays

by mrrodd

JavaScript

var labels = ["In Progress", "On Hold - Internal Reasons", "Submitted", "Approved", "New", "On Hold - External Reasons", "Pending - Portal"];
var values = [1, 2, 4, 300000001, 100000000, 300000009, 300000011];

// create a JS object from the two arrays
var statusReason = {};
for (var i = 0; i < labels.length; i++) {
    statusReason[labels[i].replace(/[^a-z]/gi, "")] = values[i];
}

var uiSelection = 4;
//var json = JSON.stringify(statusReason);

if (uiSelection == statusReason.Submitted)
    console.log("Yes");
else
    console.log("No");

console.log(statusReason);
console.log(statusReason.Submitted);