-
-
Save fazt/c73dcfac1bac56d71747372b0f65b56d to your computer and use it in GitHub Desktop.
array methods ES2023
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 numbers = [10, 35, 55, 70, 80, 100, 20, 30]; | |
| // findIndex | |
| // const index = numbers.findIndex((number) => { | |
| // console.log("n", number); | |
| // return number === 100; | |
| // }); | |
| // console.log({ index }); | |
| // findLastIndex | |
| const index = numbers.findLastIndex((number) => { | |
| console.log("n", number); | |
| return number === 100; | |
| }); | |
| console.log({ index }); |
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 numbers = [10, 35, 55, 70, 80, 100, 20, 30]; | |
| // find | |
| // const foundNumber = numbers.find((number) => { | |
| // console.log("n", number); | |
| // return number === 100; | |
| // }); | |
| // console.log({ foundNumber }); | |
| // findLast | |
| const foundNumber = numbers.findLast((number) => { | |
| console.log("n", number); | |
| return number === 100; | |
| }); | |
| console.log({ foundNumber }); |
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 numbers = [1, 2, 3, 4, 5]; | |
| // numbers.reverse(); | |
| // console.log(numbers); | |
| const numbers = [1, 2, 3, 4, 5]; | |
| const newNumbers = numbers.toReversed(); | |
| console.log(numbers); | |
| console.log(newNumbers); |
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 numbers = [11, 5, 7, 23, 44, 12, 10]; | |
| // const sortedNumbers = numbers.sort((a, b) => a - b); | |
| // console.log(numbers) | |
| // console.log(sortedNumbers) | |
| const numbers = [11, 5, 7, 23, 44, 12, 10]; | |
| const sortedNumbers = numbers.toSorted((a, b) => a - b); | |
| console.log(numbers) | |
| console.log(sortedNumbers) |
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 flowers = ["Lily", "Daisy", "Iris", "Lotus", "Allium"]; | |
| // //old way of updating an array; | |
| // flowers [4]='Rose'; | |
| // console.log(flowers); | |
| const updatedFlowers = flowers.with(4, "Aster"); | |
| console.log(flowers); | |
| console.log(updatedFlowers); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Muchas gracias por el aporte.