Lodash是一个JavaScript库,可在Underscore.js的顶部使用。 Lodash帮助处理数组,字符串,对象,数字等。_.last()方法用于获取数组的最后一个元素,即第(n-1)个元素。
用法:
lodash.last( array )
参数:此函数接受单个参数,即数组。
返回值:它返回数组的最后一个元素。
注意:在使用以下给定代码之前,请通过npm install lodash安装lodash模块。
范例1:
javascript
// Requiring the lodash library 
const _ = require("lodash"); 
  
// Original array 
let array1 = ["a", "b", "c", "d", "e"] 
  
// Using _.last() method 
let value = _.last(array1); 
  
// Printing original Array 
console.log("original Array1:", array1) 
  
// Printing the value 
console.log("value:", value)输出:

范例2:
javascript
// Requiring the lodash library 
const _ = require("lodash"); 
  
// Original array 
let array1 = [] 
  
// Using _.last() method 
let value = _.last(array1); 
  
// Printing original Array 
console.log("original Array1:", array1) 
  
// Printing the value 
console.log("value:", value)输出:

相关用法
- Lodash _.take()用法及代码示例
 - Lodash _.xor()用法及代码示例
 - Lodash _.nth()用法及代码示例
 - Lodash _.takeRight()用法及代码示例
 - Lodash _.fromPairs()用法及代码示例
 - Lodash _.sortedLastIndex()用法及代码示例
 - Lodash _.differenceBy()用法及代码示例
 - Lodash _.pullAt()用法及代码示例
 - Lodash _.remove()用法及代码示例
 - Lodash _.findIndex()用法及代码示例
 - Lodash _.pull()用法及代码示例
 - Lodash _.intersectionWith()用法及代码示例
 - Lodash _.pullAll()用法及代码示例
 - Lodash _.head()用法及代码示例
 - Lodash _.sampleSize()用法及代码示例
 - Lodash _.find()用法及代码示例
 - Lodash _.chunk()用法及代码示例
 - Lodash _.zipObject()用法及代码示例
 - Lodash _.zipWith()用法及代码示例
 - Lodash _.cloneDeep()用法及代码示例
 
注:本文由纯净天空筛选整理自tarun007大神的英文原创作品 Lodash _.last() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
