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
0

get last element in array javascript

var my_array = /* some array here */;
var last_element = my_array[my_array.length - 1];
Posted by: Guest on November-30-2020

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

Code answers related to "Javascript"

Browse Popular Code Answers by Language