lodash 分装了很多好的方法,用起来很方便
官网:
https://www.lodashjs.com/
https://www.html.cn/doc/lodash/4.15.0.html#_mapcollection-iteratee_identity
使用步骤:
1安装模块 npm i --save lodash
2在使用的地方引入模块 import lodash from ‘lodash’;
3看文档使用
下面是一些常用的函数
代码:
_.find 找到数组汇总满足条件的一个元素返回
/**
* 测试 _.find
* 返回满足条件的第一个的元素(对象)
*/
method7() {
let zhhArray = [
{'user': 'barney', 'age': 36, 'active': true},
{'user': 'fred', 'age': 40, 'active': false},
{'user': 'pebbles', 'age': 1, 'active': true}
];
// 第一个参数是 数组,第二个参数是个函数(zhh指的是 zhhArray 中的元素)