where
优质
小牛编辑
141浏览
2023-12-01
Creates a new sequence whose values are the elements of this sequence with property names and values matching those of the specified object.
Signature
Sequence.where = function(properties) { /*...*/ }
Sequence.where = function where(properties) { return this.filter(properties); }
Name | Type(s) | Description |
---|---|---|
properties | Object | The properties that should be found on every element that is to be included in this sequence. |
returns | Sequence | The new sequence. |
Examples
var people = [ { first: "Dan", last: "Tao" }, { first: "Bob", last: "Smith" } ]; Lazy(people).where({ first: "Dan" }) // sequence: [{ first: "Dan", last: "Tao" }]
Benchmarks
var animals = ["dog", "cat", "mouse", "horse", "pig", "snake"]; Lazy(animals).where({ length: 3 }).each(Lazy.noop) // lazy _.each(_.where(animals, { length: 3 }), _.noop) // lodash
Implementation | Ops/second |
---|---|
lazy | |
lodash |