Using Underscorejs, would anyone know how to simply replace one attribute of an object?
For example, if I have this:
var obj = {
"id" : 123,
"date" : 142002020,
"name" : "somename",
"active" : 1
}
Now I want to set active to 0;
I could use _.collect and check for ‘active’ then update it and return to a new variable, but it seems like there’s a better way, I’m just not seeing it.
Thanks!
Why don’t you just
obj['active'] = 0, you don’t need underscore for changing an property.EDIT
If you need to find a nested key maybe you could use a recursive function.