美文网首页
3 Methods To Get The Last Elemen

3 Methods To Get The Last Elemen

作者: onbug | 来源:发表于2018-07-02 17:43 被阅读0次
var myArray = [1,2,3,4,5,6];

// Fastest method, requires the array is in a variable
myArray[myArray.length - 1];

// Also very fast but it will remove the element from the array also, this may or may not matter in your case.
myArray.pop();

// Slowest but very readable and doesn't require a variable
myArray.slice(-1)[0]

相关文章

网友评论

      本文标题:3 Methods To Get The Last Elemen

      本文链接:https://www.haomeiwen.com/subject/oniluftx.html