Scott
0
Q:

javascipt get last element of array

var foods = ["kiwi","apple","banana"];
var banana = foods[foods.length - 1]; // Getting last element
37
var colors = ["red","blue","green"];
var green = colors[colors.length - 1];//get last item in the array
50
var numbers = ["one", "two", "three"];
var lastnumber = numbers[numbers.length - 1];
console.log(lastnumber);
10
var colors = ["red","blue","green"];
var green = colors[colors.length - 1]; //get last item in the array
24
const arr = [1,2,3] ;
console.log(arr[arr.length - 1]);
6
arr.slice(-1)[0] 
4
var array =[1,2,3,4];
var last= array[array.length-1];
1
this = array[array.length - 1];
1
var last = arr.slice(-1)[0]
1
var array = [1,2,3,4,5,6];
var val = array[array.length - 1]; // 6
1

New to Communities?

Join the community