Heres the situation -
I have an Array and an Object.
say:
var Array = ["field1", "field2", "field3"];
var Object = { field1: undefined, field2: undefined, field3: undefined, field4: undefined, field5: undefined}
*the values in the object don't really matter right now
Using underscoreJS i want to iterate over the Object and check to see if each of the keys exists in the Array array. If it does i want to be able to set its value to true and if not i want to set it to false.
So far i've tried:
_.mapObject(Object, function(val, key){
for (var j = 0; j < Array.length; j++) {
currentKey = Array[j];
(function(i){
for (var k = 0; k < Array.length; k++) {
if(key === Array[i]) {
return val = true;
} else {
return val = false;
}
}
})(currentKey);
}
});
Shit is very confusing; for me at least. Any help is appreciatated.
Objectand your arraysArray, as that are the built-in class* names and you're likely to get lots of funny errors later. Instead, how aboutobjandarr?return falseif only one of the keys is not the same.