undefined
if no element was removed. Otherwise, returns the removed element or an object with the removed element and index if returnIndex
is true.
const array = [1, 2, 3, 4, 5]
const r1 = removeLast(array, (v) => v === 3)
console.log(array, r1) // [1, 2, 4, 5] , 3
const r2 = removeLast(array, (v) => v === 6)
console.log(array, r2) // [1, 2, 4, 5] , undefined
const r3 = removeLast(array, (v) => v > 1)
console.log(array, r3) // [1, 2, 4] , 5
const array = [1, 2, 3, 4, 5]
// Pass `true` as the third argument.
const r1 = removeLast(array, (v) => v > 1, true)
console.log(array, r1) // [1, 2, 3, 4] , { item: 5, index: 4 }
const r2 = removeLast(array, (v) => v > 4, true)
console.log(array, r2) // [1, 2, 3, 4] , undefined
Generated using TypeDoc
Finds the last element that matches a predicate and removes it by mutating the array in-place.