lodash是一个一致性、模块化、高性能的 javascript 实用工具库。
lodash 通过降低 array、number、objects、string 等等的使用难度从而让 javascript 变得更简单。lodash 的模块化方法 非常适用于:
import lodash from 'lodash';
方法
-1
。var users = [ { 'user': 'barney', 'active': false }, { 'user': 'fred', 'active': false }, { 'user': 'pebbles', 'active': true } ]; _.findindex(users, function(o) { return o.user == 'barney'; }); // => 0 // the `_.matches` iteratee shorthand. _.findindex(users, { 'user': 'fred', 'active': false }); // => 1 // the `_.matchesproperty` iteratee shorthand. _.findindex(users, ['active', false]); // => 0 // the `_.property` iteratee shorthand. _.findindex(users, 'active'); // => 2
-1
。var users = [ { 'user': 'barney', 'active': true }, { 'user': 'fred', 'active': false }, { 'user': 'pebbles', 'active': false } ]; _.findlastindex(users, function(o) { return o.user == 'pebbles'; }); // => 2 // the `_.matches` iteratee shorthand. _.findlastindex(users, { 'user': 'barney', 'active': true }); // => 0 // the `_.matchesproperty` iteratee shorthand. _.findlastindex(users, ['active', false]); // => 2 // the `_.property` iteratee shorthand. _.findlastindex(users, 'active'); // => 0
value
在数组中的索引位置, 没有找到为返回-1
。_.indexof([1, 2, 1, 2], 2); // => 1 // search from the `fromindex`. _.indexof([1, 2, 1, 2], 2, 2); // => 3
array
. 反转array
,使得第一个元素变为最后一个元素,第二个元素变为倒数第二个元素,依次类推。
var array = [1, 2, 3]; _.reverse(array); // => [3, 2, 1] console.log(array); // => [3, 2, 1]
裁剪数组array
,从 start
位置开始到end
结束,但不包括 end
本身的位置。
array
(array): 要裁剪数组。[start=0]
(number): 开始位置。[end=array.length]
(number): 结束位置。 (array): 返回 数组array
裁剪部分的新数组。
如对本文有疑问, 点击进行留言回复!!
微信小程序wx.scanCode扫描条形码,偶尔出现条形码不正确导致查询失败
Android 入门第七讲01-数据存储(数据存储概述,文件存储(raw和asserts目录读写,data/data/包名目录读写,sdcard目录读写),SharedPreferences读写)
vue-axios系列:axios拦截器,配置请求头,配置请求参数
网友评论