js array last element
var colors = ["red","blue","green"];
var green = colors[colors.length - 1];//get last item in the arrayvar my_array = /* some array here */;
var last_element = my_array[my_array.length - 1];var foods = ["kiwi","apple","banana"];
var banana = foods[foods.length - 1]; // Getting last elementvar colors = ["red","blue","green"];
var green = colors[colors.length - 1];//get lastvar numbers = ["one", "two", "three"];
var lastnumber = numbers[numbers.length - 1];
console.log(lastnumber);array.slice(-1)[0]
Also in JavaScript:
- js find array return true false
- javascript ascending and descending
- find unique elements in array javascript
- js fill string with n characters
- new file shortcut vscode
- javascript date difference in months
- merge objects javascript es6
- javascript upload file button
- parent folder of file extendscript
- string split javascript newline
- how to make a show password button
- return last two values of array in javascript
- how to remove key value pair from object js
- javascript event bind dynamic element
- js get element padding
- Setting axios base url dynamically
- loopback model properties default
- how to print the value of variable in javascript in html
- angular serve
- remove last character from string jquery
- capitalize in javascript
- prepen an element js
- jquery count elements
- conditional chaining chrome