JS Built-ins
← Array78 / 226
ArrayArray.prototype.findLastintermediate

Array.prototype.findLast() β€” last active user

πŸ“– Usage Example
const logs = [{type:'err'}, {type:'info'}, {type:'err'}]
logs.findLast(l => l.type === 'err')  // β†’ {type:'err'} (last one)

Use findLast() to locate the most recent object in an array matching a property condition.

Array.prototype.findLast() β€” objects

Like find(), findLast() works on any element type, including objects. It returns the last object in the array that satisfies the predicate.

Challenge: Implement findLastActive(users) that returns the last user with active: true.

findLastActive([{name:'A',active:true},{name:'B',active:false},{name:'C',active:true}])
// β†’ {name:'C', active:true}
πŸ’‘ Hints (2)
  • β€’ `findLast` traverses from the end, so it naturally finds the last matching object.
  • β€’ The predicate is identical to what you would write for `find` β€” just the traversal direction differs.