last index array javascript
snippet in javascript

last index array javascript

user2603

var colors = ["red","blue","green"];
var green = colors[colors.length - 1]; //get last item in the array

last item in array javascript

user4416

const array = ['a', 's', 'd', 'f'];
const last = array.pop(); 
console.log(last); // Returns 'f'
console.log(array); // Returns ['a', 's', 'd']