Answers for "javascript last object of array"

25

javascript last element of array

let arr = [1,2,3]
arr[arr.length - 1] //returns last element in an array
Posted by: Guest on June-16-2020
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 "javascript last object of array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language