Get the last item in an array

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

    if (loc_array[loc_array.length - 1] === 'index.html') {
       // do something
    } else {
       // something else
    }
    

    In the event that your server serves the same file for "index.html" and "inDEX.htML" you can also use: .toLowerCase().

    Though, you might want to consider doing this server-side if possible: it will be cleaner and work for people without JS.

提交回复
热议问题