Get the last item in an array

前端 未结 30 2715
执念已碎
执念已碎 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:41

    const lastElement = myArray[myArray.length - 1];
    

    This is the best options from performance point of view (~1000 times faster than arr.slice(-1)).

提交回复
热议问题