Javascript get last item in array
snippet in javascript

javascript get last element of array

user2668

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

Javascript get last item in array

user1949

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

javascript get last element of array

user2054

var foods = ["kiwi","apple","banana"];
var banana = foods[foods.length - 1]; // Getting last element

javascript last element of array

user9848

let arr = ['a', 'b', 'c']
arr.slice(-1)[0] // returns last element in an array

get last item in array javascript

user7775

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

javascript take last element of array

user9037

let array = [1,2,3,4,5];
let lastElement = array.pop();

// array -> [1,2,3,4];
// lastElement = 5;