Get the last item in an array

前端 未结 30 3211
执念已碎
执念已碎 2020-11-22 05:28

Here is my JavaScript code so far:

var linkElement = document.getElementById(\"BackButton\");
var loc_array = document.location.href.split(\'/\');
var newT =         


        
30条回答
  •  借酒劲吻你
    2020-11-22 05:54

    In ECMAScript proposal Stage 1 there is a suggestion to add an array property that will return the last element: proposal-array-last.

    Syntax:

    arr.lastItem // get last item
    arr.lastItem = 'value' // set last item
    
    arr.lastIndex // get last index
    

    You can use polyfill.

    Proposal author: Keith Cirkel(chai autor)

提交回复
热议问题