Last active
October 28, 2021 01:15
-
-
Save tonkotsuboy/4be994ad00037deee973758fc61285e6 to your computer and use it in GitHub Desktop.
findLastIndex demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myArray = [ | |
{ name: 'ギータ', age: 32 }, | |
{ name: 'マッチ', age: 37 }, | |
{ name: 'ケイゾー', age: 37 }, | |
{ name: '高谷', age: 39 }, | |
]; | |
// myArrayから、ageが37の最後の要素を探し、名前を取得 | |
const targetName = myArray.findLast(member => { | |
return member.age === 37; | |
})?.name; | |
console.log(targetName); // ケイゾーが出力 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment