Skip to main content

Command Palette

Search for a command to run...

๐Ÿš€ Array Methods X Shaka Laka Boom Boom : A Childhood Magic in JavaScript!

A story where there is magic โœจ and coding ๐Ÿ’ป!

Published
โ€ข3 min read
๐Ÿš€ Array Methods X Shaka Laka Boom Boom :  A Childhood Magic in JavaScript!

Hellooo Techiess ! Doy you remember the excitement of watching Shaka Laka Boom Boom as a kid ? The thrill when Sanjuโ€™s magic pencil brought his drawing to life ? Imagine if JavaScript have a similar magic tool โ€” well guess what ? it does ๐Ÿช„โœจ.

Just like Sanju used his magic pencil to solve problems, fight the villains, and go on adventures with his friends. Javascript has array methods that make the coding magical !

So, in this blog we will relive our childhood memories while exploring the top 10 JavaScript array methods, i will explain you all in a fun and easy way. So grab your magic pencil ( Keyboard ), and letโ€™s start drawing some powerful code in the code editor ๐Ÿš€๐Ÿ’ป.

๐Ÿ“ 1. forEach() - Helping Friends

Sanju used his magic pencil to help his friends. Just like forEach(), which helps us to do something for every item in an array.

let friends = ["Changu", "Mangu", "Karuna", "Raju"];
friends.forEach(friend) {
console.log(`${friend} is helped !`)
}

๐Ÿ›ก 2. map() - Magic Shield

A gangster tried to steal the pencil ! Sanju quickly draw a magic shield that blocked every attack. The map() method works the same way. It changes every item in an array.

let attacks = ["Fire", "Ice", "Laser"];
let shield = attacks.map(attack => `Blocked ${attack}`) {
console.log(shield)
}

๐Ÿ˜ 3. filter() - Flying Elephant

Sanju draw a flying elephant that only carried good peoples. The filter() method also selects only the right item from an array.

let people = [
    { name: "Raju", good: true },
    { name: "Gangster Uncle", good: false },
    { name: "Karuna", good: true  }
];

let goodPeople = people.filter(person => person.good) {
console.log(goodPeople)
}

๐Ÿ‘ž 4. find() - Dancing Shoes

Sanjuโ€™s magic shoes fit only one person! The find() method also finds only the first matching item.

let shoes = [36, 38, 40, 42, 44];
let mySize = shoes.find(size => size === 42) {
console.log(mySize);
}

๐Ÿถ 5. some() - Talking Dog

Sanju draw a talking dog that barked when danger was near. The some() method checks if atleast one item matches a condition.

let noises = ["Growling", "Sighing", "Howling", "Grunting"];
let isBarking = noises.some(noise => noise === "Growling") {
console.log(isBarking); // true
}

โณ 6. every() - Time Machine

Sanju draw a time machine, but it only worked if all the buttons were correct! The every() method checks if all items in an array meet a condition.

let buttons = [true, true, true, true];
let timeMachineWorks = buttons.every(button => button === true) {
console.log(timeMachineWorks); // true
}

๐ŸŒฒ7. reduce() - Treehouse

Sanju made a treehouse by joining small wooden pieces. The reduce method combines all values in an array into one.

let woods = [2, 3, 5, 7];
let totalWood = woods.reduce((total, wood) => total + wood, 0) {
console.log(totalWood);
}

๐Ÿค– 8. Sort() - Giant Robot

Sanju draw a giant robot that arranged things in order. The sort() method also arranges values in order.

let robots = [200, 100, 500, 300];
robots.sort((a, b) => a - b);
console.log(robots);

๐Ÿ›ธ 9. splice() - A Friend Shaan

Sanjuโ€™s alien friend Shaan could remove things from the middle. The splice() method removes or replaces items in an array.

let aliens = ["Shaan", "Xylo", "Zara", "Momo"];
aliens.splice(1, 2); // Remove "Xylo" & "Zara"
console.log(aliens);

๐Ÿซ 10. concat() - Jadoo High School

Sanju and Shaan went to Jadoo High School, where two classes merged. The concat() method joins two arrays together.

let class1 = ["Sanju", "Shaan"];
let class2 = ["Raju", "Karuna"];
let jadooHigh = class1.concat(class2) {
console.log(jadooHigh);
}

๐ŸŽฏ Conclusion

ust like Sanjuโ€™s magic pencil brought things to life, these array methods transform data in JavaScript! ๐ŸŽจ๐Ÿ’ป

If you loved Shaka Laka Boom Boom and want to master JavaScript, these array methods are pure magic! ๐Ÿš€

If you enjoyed this blog, share and comment! ๐Ÿ˜‰โœจ Happy coding!