lodash常用方法笔记

  1. _.fromPairs(pairs)

与_.toPairs正好相反;这个方法返回一个由键值对pairs构成的对象。

_.fromPairs([['fred', 30], ['barney', 40]]);
// => { 'fred': 30, 'barney': 40 }

Object.fromEntries()有同样的功能,只是在高版本浏览器才支持:
在这里插入图片描述

  1. _toPairs(object)
function Foo() {
    
    
  this.a = 1;
  this.b = 2;
}
 
Foo.prototype.c = 3;
 
_.toPairs(new Foo);
// => [['a', 1], ['b', 2]] (iteration order is not guaranteed)

猜你喜欢

转载自blog.csdn.net/yexudengzhidao/article/details/132288131