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 item in array js

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

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

Code answers related to "Javascript"

Browse Popular Code Answers by Language