Created
September 17, 2021 02:50
-
-
Save hmmhmmhm/8641c6c49252119177f24c8781195de9 to your computer and use it in GitHub Desktop.
Check Map For Some
This file contains hidden or 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 list = [{ text: "a" }, { text: "b" }, { text: "c" }, { text: "d" }]; | |
| // Map & Filter | |
| const i1 = list | |
| .map((item, index) => (item.text === "c" ? index : null)) | |
| .filter((item) => item !== null)[0]!; | |
| // For | |
| let i2 = 0; | |
| for (const item of list) { | |
| if (item.text === "c") { | |
| i2 = list.indexOf(item); | |
| break; | |
| } | |
| } | |
| // Some | |
| let i3 = 0; | |
| list.some((item, index) => { | |
| if (item.text == "b") { | |
| i3 = index; | |
| return true; | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment