Answers for "get last element of array javascript................."

25

get last element of array javascript

// Method - 1 ([] operator)
const arr = [5, 3, 2, 7, 8];
const last = arr[arr.length - 1];
console.log(last);
/*
    Output: 8
*/

// Method - 2 (Destructuring Assignment)
const arr = [5, 3, 2, 7, 8];
Posted by: Guest on February-23-2021

Code answers related to "get last element of array javascript................."

Code answers related to "Javascript"

Browse Popular Code Answers by Language