Two part question about similar problems. I\'ve got 2 different arrays,
array 1:
array1 = [{
name : \"users\",
checked :
You can't do this without looping over the elements, however there are functional abstractions you can use instead of for:
For array 1, you can use map
array1.map(function(x) {
x.checked = true;
return x
});
Or using _.map from lodash:
_.map(array1, function(x) {
x.checked = true;
return x
});
For array 2 you can use _.mapValues from lodash.
_.mapValues(array2[0], function() {
return true;
});
You can see that lodash implements _.map using while at https://github.com/lodash/lodash/blob/a1b15df6489f47498edda244552c9804e046a45d/lodash.js#L3125