toObject
优质
小牛编辑
140浏览
2023-12-01
Creates an object from a sequence of key/value pairs.
Signature
Sequence.toObject = function() { /*...*/ }
Sequence.toObject = function toObject() { return this.reduce(function(object, pair) { object[pair[0]] = pair[1]; return object; }, {}); }
Name | Type(s) | Description |
---|---|---|
returns | Object | An object with keys and values corresponding to the pairs of elements in the sequence. |
Examples
var details = [ ["first", "Dan"], ["last", "Tao"], ["age", 29] ]; Lazy(details).toObject() // => { first: "Dan", last: "Tao", age: 29 }