Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code for video on Array.prototype findLast and findLastIndex
// Array.prototype.find() node v4.9.1
// Array.prototype.findIndex() v4.9.1
// Array.prototype.findLast() node v18.12.1+
// Array.prototype.findLastIndex() node v18.12.1+
const names = [
{ name: 'Rachel' },
{ name: 'Ross' },
{ name: 'Chandler' },
{ name: 'Phoebe' },
{ name: 'Joey' },
{ name: 'Monica' },
{ name: 'Julian' },
{ name: 'Bubbles' },
{ name: 'Ricky' },
];
const bestFriend = 'Bubbles';
function findAFriend(obj, index) {
//looking for a match between `bestFriend` and `name`.
console.log(index);
if (obj.name === bestFriend) return true;
//undefined
}
let n = names.findLast(findAFriend);
let i = names.findLastIndex(findAFriend);
console.log(n, i);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment