❌ Get last array item
01 Dec, 2023
const arr = [1, 2, 3, 4]
const last = arr[arr.length - 1]
console.log(last) // 4
const arr = [1, 2, 3, 4]
const last = arr.at(-1)
console.log(last) // 4
const arr = [1, 2, 3, 4]
const last = arr.findLast((x) => true)
console.log(last) // 4
const arr = [1, 2, 3, 4]
const last = arr.slice(-1)[0]
console.log(last) // 4
← Back home