7. lodash

1/8/2023 js

# lodash函数

first / last / toUpper / reverse / each / includes / find / findIndex

const _ = require('lodash')
const arr = ['jack', 'tom', 'luck', 'lily']

console.log(_.first(arr))
console.log(_.last(arr))
console.log(_.toUpper(_.first(arr)))

// 注意:lodash中的reverse方法调用的是数组中的reverse方法,数组中的reverse方法会改变原数组,不是纯函数
// lodash是一个功能库,提供了方便操纵数组、字符串的方法。lodash中的fp模块提供的函数才是纯函数
console.log(_.reverse(arr))


// each接受两个参数(数组,回调函数)
const r = _.each(arr, (item, index) => {
  console.log('each', item, index)
})
console.log('r', r)


// includes、find、findIndex是es6新增的方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
最近更新时间: 2/4/2023, 10:01:08 AM
강남역 4번 출구
Plastic / Fallin` Dild