get the last element of array javascript
var colors = ["red","blue","green"];
var green = colors[colors.length - 1];//get last item in the arrayconst heroes = ["Batman", "Superman", "Hulk"];
const lastHero = heroes.pop(); // Returns last elment of the Array
// lastHero = "Hulk"arr.slice(-1)[0] var colors = ["red","blue","green"];
var green = colors[colors.length - 1]; //get last item in the array
let array = [1,2,3,4,5];
let lastElement = array.pop();
// array -> [1,2,3,4];
// lastElement = 5;if (loc_array[loc_array.length - 1] === 'index.html') {
// do something
} else {
// something else
}
Also in JavaScript:
- bcript laravel
- js is empty object
- set dynamic route in link react js
- how to check if a number is negative in p5.js
- javascript not empty array not string
- how to get the computer date and time jquery
- js object properties
- react reducer hooks
- canvas container page offset
- javascript convert number to spreadsheet column
- discord.js lockdown command
- convert date to string javascript
- moment js year only
- double matrix iteration in react
- array vowels js
- javascript stop execution
- jquery get textarea value
- jquery if attribute
- discord.js find word inside comment
- how to use react-fontawesome
- react native text wrap
- deploy react to aws
- adding prod environment file in angular8
- what is react native