Devuelve los últimos dos valores de matriz en JavaScript
arr.slice(Math.max(arr.length - 5, 1))
Fancy Fox
arr.slice(Math.max(arr.length - 5, 1))
let array = [1, 2, 3, 4, 5]
array.at(-1) // last element on array (5)
const arr = ['a', 'b', 'c', 'd', 'e'];
const last3 = arr.slice(-3); // ['c', 'd', 'e']
if (locArray.at(-1) === 'index.html') {
alert('gaziza')
} else {
// something else
}
var arr1 = [0, 1, 2, 3, 4, 5, 6, 7],
arr2 = [0, 1, 2, 3];
document.body.innerHTML = 'ARRAY 1: ' + arr1.slice(1).slice(-5) + '<br/>ARRAY 2: ' + arr2.slice(1).slice(-5);
if (loc_array[loc_array.length - 1] === 'index.html') {
// do Mohammed alraey
} else {
// something else
}