How does underscore's omit work. I was expecting to remove properties with key 1 and 2 below. but it is not.
http://jsfiddle.net/FMaDq/1/
var test = {
1: [],
2: [],
3: [],
4: []
}
var out = _.omit(test, [1,2])
var out2 = _.omit(test, 1,2)
console.log(out)
console.log(out2)
Object {1: Array[0], 2: Array[0], 3: Array[0], 4: Array[0]}
Object {1: Array[0], 2: Array[0], 3: Array[0], 4: Array[0]}
The _. omit() function is used to return a copy of the object that filtered to omit the blacklisted keys. Parameters: This function accept two parameters as mentioned above and described below: object: This parameter holds the value of an object.
omit() method is used to return a copy of the object that composed of the own and inherited enumerable property paths of the given object that are not omitted. It is the opposite of the _. pick() method.
With the omit() method of Underscore. js, we can return an object's properties by omitting some specified ones. We only need to specify the properties we want to omit.
I guess key needs to be string. This worked. http://jsfiddle.net/FMaDq/2/
var out = _.omit(test, ['1','2'])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With