Get the last item in an array

前端 未结 30 2749
执念已碎
执念已碎 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 06:01

    I generally use underscorejs, with it you can just do

    if (_.last(loc_array) === 'index.html'){
      etc...
    }
    

    For me that is more semantic than loc_array.slice(-1)[0]

提交回复
热议问题