how to get the last element of an array in javascript
arr.slice(-1)[0] const nums = [1, 2, 3, 4, 5, 6, 7];
const lastOne = nums[nums.lenght - 1]; // last element of arrayBest IDE for Web Developers in Visual Studio Codeif (loc_array[loc_array.length - 1] === 'index.html') {
// do something
} else {
// something else
}const heroes = ["Batman", "Superman", "Hulk"];
const lastHero = heroes.pop(); // Returns last elment of the Array
// lastHero = "Hulk"var colors = ["red","blue","green"];
var green = colors[colors.length - 1];//get last item in the array
Also in JavaScript:
- javascript dom elements
- stopper un intervalle javascript
- jquery droppable allow what can be dropped
- JSONDecoder
- string methods javascript
- knex js join schema
- jsx full form
- how to terminate a program in js
- advanced data manipulation javascript
- how to scroll through an object js
- npm windows shocut
- angular 9 dockerfile
- smooth scroll react
- setstate react js
- how to run javascript in terminal
- get variable name javascript
- reverse a linked list js
- javascript unknown number of parameters
- style an element with javascript
- How do I redirect to another webpage
- disable right click jquery
- useHistory react-router-dom
- express middleware pass parameter
- angular material input