how to get the last element of an array in js code example
Example 1: javascript get last element of array
var foods = ["kiwi","apple","banana"];
var banana = foods[foods.length - 1];
Example 2: javascript last element of array
let arr = ['a', 'b', 'c']
arr.slice(-1)[0]
Example 3: how to get the last eleemnt of an array
var Cars = ["Volvo", "Mazda", "Lamborghini", "Maserati"];
var hmCars = Cars.pop();
console.log(hmCars)
Example 4: get last element of array javascript
var numbers = ["one", "two", "three"];
var lastnumber = numbers[numbers.length - 1];
console.log(lastnumber);
Example 5: js get last array element
const array = [1, 2, 3, 4]
const lastArrayElement = array[array.length - 1]
Example 6: javascript get last element of array
console.log(2)