how to access the last element of an array code example

Example 1: how to get last element of array

return array[array.length - 1];

Example 2: Javascript get last item in array

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

Example 3: get last element of array javascript

arr.slice(-1)[0]

Example 4: get last item in array javascript

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

Example 5: javascript get last element in an array

var last = arr[arr.length - 1]

Example 6: how to select last element in a array

int[] karunakar={1,2,3};
System.out.println(karunakar[karunakar.length-1]);

Tags:

Java Example