I am trying to populate an array with the text value of a json obejct based off values from another array
my code is:
var DemoOptions = {
"One" : 1,
"Two" : 2,
"Three" : 3,
"Four" : 4,
"Five" : 5
};
var OldArray = [1,3,5];
var NewArray = [];
$.each(OldArray,function(x, item){
NewArray.push(DemoOptions.item);
});
NewArray should now be:
NewArray ["One", "Three", "Five"]
If DemoOptions was flipped like:
you could do this very easily, because you just need to iterate through
OldArrayone and push the respective value (mapped byDemoOptions) intoNewArray. Since there is probably a good reason you have it the other way, you should create this flipped copy dynamically and then fill your new array: