Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

get last index of array

const arr = [2, 4, 6, 8, 10, 12, 14, 16];

const lastElement1 = arr[arr.length - 1];  // Method 1
const lastElement2 = arr.slice(-1);  //Method 2
const lastElement3 = arr.pop(); //Method 3
const lastElement4 = arr.at(-1) //Method 4 Best Approach
Source by flexiple.com #
 
PREVIOUS NEXT
Tagged: #index #array
ADD COMMENT
Topic
Name
7+4 =