Last active
September 3, 2021 15:07
-
-
Save tararoutray/fd5b2efe669091f2d8b83dee94a32db3 to your computer and use it in GitHub Desktop.
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
// Array.from() | |
// The Array.from() method returns an Array object from any object with a length property or any iterable object. | |
// Following will return ["A", "I", "L", "J", "S", "I", "6", "4", "6", "8", "5"] | |
Array.from("AILJSI64685"); | |
// Array.keys() | |
// The Array.keys() method returns an Array Iterator object with the keys of an array. | |
const fruits = ["Avocado", "Kiwi", "Apple", "Mango"]; | |
const fruitsKeys = fruits.keys(); | |
let keys = ''; | |
for (let fruitKey of fruitsKeys) { | |
keys += fruitKey + ', '; | |
} | |
// Following will print: 0, 1, 2, 3 | |
console.log(keys); | |
// Array.find() | |
// The find() method returns the value of the first array element that passes a test function. | |
// The below snippet finds the first element that is larger than 3: | |
const numbers = [1, 2, 3, 4, 5]; | |
let firstElement = numbers.find((value, index, array) => value > 3); | |
// Following will print: 4 | |
console.log(firstElement); | |
// Array.findIndex() | |
// The findIndex() method returns the index of the first array element that passes a test function. | |
// The below snippet finds the index of the first element that is larger than 3: | |
const numbers = [1, 2, 3, 4, 5]; | |
let firstIndex = numbers.findIndex((value, index, array) => value > 3); | |
// Following will print: 3 | |
console.log(firstIndex); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment