Answers for "output the last element of the array, without knowing the array length."

2

how to print the last element of an array

var array = [1,2,3,4,5];
var last_element = array[array.length - 1];
console.log(last_element); //Expected Output: 5
Posted by: Guest on January-20-2021
1

Get the last item in an array

if (loc_array[loc_array.length - 1] === 'index.html') {
   // do something
} else {
   // something else
}
Posted by: Guest on January-24-2021

Code answers related to "output the last element of the array, without knowing the array length."

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language