last item in array javascript

JavaScript
var my_array = /* some array here */;
var last_element = my_array[my_array.length - 1];arr.slice(-1)[0] var colors = ["red","blue","green"];
var green = colors[colors.length - 1];//get lastvar colors = ["red","blue","green"];
var green = colors[colors.length - 1]; //get last item in the array
// Find the last item in an array.
arrayName[arrayName.length - 1]const array = ['a', 's', 'd', 'f'];
const last = array.pop(); 
console.log(last); // Returns 'f'
console.log(array); // Returns ['a', 's', 'd']
Source

Also in JavaScript: