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

toObject

优质
小牛编辑
145浏览
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;
  }, {});
}
NameType(s)Description
returnsObject

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 }