Lets say I have an object
filter: {
\"ID\": false,
\"Name\": true,
\"Role\": false,
\"Sector\": true,
\"Code\": false
}
Using lodash, mapValues
is a graceful, loop-free way:
filter = {
"ID": false,
"Name": true,
"Role": false,
"Sector": true,
"Code": false
};
filter = _.mapValues(filter, () => false);
If you want to do this with Underscore.js, there is an equivalent, but with a slightly different name:
filter = _.mapObject(filter, () => false);
In either case, the value of filter
will be set to:
{ ID: false,
Name: false,
Role: false,
Sector: false,
Code: false }