当前位置: 首页 > 文档资料 > Lazy.js 英文文档 >

where

优质
小牛编辑
139浏览
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);
}
NameType(s)Description
propertiesObject

The properties that should be found on every element that is to be included in this sequence.

returnsSequence

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
ImplementationOps/second
lazy
lodash