We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
AS
JavaScript Array Methods
Every Developer Should Know1. push() - Adding to the Array Party
This method is like an inviter adding more
guests to a party.
With .push(), you can effortlessly add one or
more elements to the end of an array.
st friends = [‘Alice’, ‘Bob’];
Sie Ce Ten regis eC MPD UE CD
console. log(friends) ;2. pop() - Saying Goodbye to the Last
Guest
Think of this method as the party ending,
and the last guest leaving.
-pop() removes the last element from an
array and gives it back to you.
st colors = [‘red’, ‘blue’, ‘green'];
Been col emt eto
CLs ere C
Fel os CEB Coot3. forEach() - Looping Made Easy
This method is like a tour guide for arrays.
Instead of manually visiting each
element, .forEach() takes you through each
one.
nst fruits = [‘apple’, ‘banana’, ‘cherry'];
care Cia aeoan
console. log(fruit) ;
oF4. map() - Transforming Lists
Want to change every item in an array?
The .map() method is your magic wand.
ist numbers = [1, 2, 3];
st doubled = [Link](num => num * 2);
oer C tp5. filter() - Picking What You Need
Think of this as a sieve that filters out items
you don't need from an array.
ages = [1
Pree oe Cre eee
console. log(adults) ;6. find() - Seek and You Shall Find
When you need to find the first item that
matches your criteria in an array, .find()
comes to your rescue.
books = ['Moby Dick’, ‘The Great Gats! PCE
Se ree eee (Cr eee Td Recs ab
console. 1og(findGatsby);7. reduce() - Simplify Your Data
It's like a magic pot that takes a lot and
gives you a little.
Sum up, reduce, and simplify your array
elements into a single value.
numbers = [1, 2, 3, 4]5
ve a ((total, num) => total + num, 0);
console. 1og(sum) ;