JavaScript obtenga el último elemento de matriz
var colors = ["red","blue","green"];
var green = colors[colors.length - 1];//get last item in the array
Friendly Hawk
var colors = ["red","blue","green"];
var green = colors[colors.length - 1];//get last item in the array
console.log([1,2,3,4].reverse()[0]);
var last = arr.slice(-1)[0]
var last = arr[arr.length - 1]
var name = ["jon","tem","kevin", "ramos"];
var lastNameInArray = name[name.length - 1];// >> ramos
if (locArray.at(-1) === 'index.html') {
// do something
} else {
// something else
}
const lastItem = colors[colors.length - 1]
var last = arr.slice(-1)[0]
let arry = [2, 4, 6, 8, 10, 12, 14, 16];
let lastElement = arry[arry.length - 1];
console.log(lastElement);
//Output: 16
var example = ["element_1","element_2","element_3"]
var third = example[example.length - 1]