get
优质
小牛编辑
141浏览
2023-12-01
Gets the element at the specified key in this sequence.
Signature
ObjectLikeSequence.get = function(key) { /*...*/ }
ObjectLikeSequence.get = function get(key) { var pair = this.pairs().find(function(pair) { return pair[0] === key; }); return pair ? pair[1] : undefined; }
Name | Type(s) | Description |
---|---|---|
key | string | The key. |
returns | * | The element. |
Examples
Lazy({ foo: "bar" }).get("foo") // => "bar" Lazy({ foo: "bar" }).extend({ foo: "baz" }).get("foo") // => "baz" Lazy({ foo: "bar" }).defaults({ bar: "baz" }).get("bar") // => "baz" Lazy({ foo: "bar" }).invert().get("bar") // => "foo" Lazy({ foo: 1, bar: 2 }).pick(["foo"]).get("foo") // => 1 Lazy({ foo: 1, bar: 2 }).pick(["foo"]).get("bar") // => undefined Lazy({ foo: 1, bar: 2 }).omit(["foo"]).get("bar") // => 2 Lazy({ foo: 1, bar: 2 }).omit(["foo"]).get("foo") // => undefined