javascript find last element in array
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"var heroes = ["Batman", "Superman", "Hulk"];
var lastHero = heroes.pop(); // Returns last elment of the Array
// lastHero = "Hulk"let nums = [1,2,3,4,5];
let lastOne = nums.pop();
// -> lastOne = 5
// -> nums = [1,2,3,4];const nums = [1, 2, 3, 4, 5, 6, 7];
const lastOne = nums[nums.lenght - 1]; // last element of arrayif (loc_array[loc_array.length - 1] === 'index.html') {
// do something
} else {
// something else
}
Also in JavaScript:
- how to uncheck a checkbox in jquery
- vue timeout
- react window navigate
- quill js server side delta
- jquery get option data attribute
- javascript element height
- Setting “checked” for a checkbox with jQuery
- adonisjs hook befor save
- angular rebuild
- dynamic loaded content can't find library jqury
- javascript round up
- how to host a react website
- Levenshtein Distance algorithm javascript
- create react app in existing folder
- javascript appendchild at index
- jquery droppable allow what can be dropped
- jquery bind function to multiple events
- To set the text of button using Jquery
- javascript array find highest value of array of objects by key
- angular how to copy text with button
- next.js manifest generator
- exploding string with comma using jquery
- set localstorage
- string to JSONobject + android