Hello Dev Community! ๐
Today marks Day 14 โ exactly two full weeks of documenting my journey toward mastering the MERN stack! Today, I wrapped up the second half of Lecture 4 of Apna College's JavaScript playlist with Shradha Didi, focusing on Array Methods.
Yesterday was about understanding array structures; today was about actively manipulating them using built-in functions.
๐ง Key Learnings From JS Lecture 4 (Array Methods)
I experimented with several crucial array methods that allow us to add, remove, and alter items on the fly. Shradha Didi divided them into two main categories:
- Basic Add / Remove Methods
-
.push(): Adds one or more elements to the end of an array (changes the original array). -
.pop(): Removes the last element from the end of an array and returns it. -
.unshift(): Adds an element to the start of an array (shifts all indexes forward). -
.shift(): Removes the first element from the start of an array.
- Advanced Manipulation Methods
-
.toString(): Converts an array into a single comma-separated string. -
.concat(): Merges multiple arrays together into a brand-new array without changing the original ones. -
.slice(start, end): Extracts a regular chunk of an array without changing the original structure. -
The Powerhouseโ
.splice(start, delCount, newElements): This method is incredible. It can delete, add, or replace elements at any specific index inside the original array.
๐ ๏ธ What I Actually Code / Practiced
I spent my practice session solving the real-world array manipulation assignment from the lecture:
-
The Companies Array Challenge: Created an array storing a list of tech corporations:
["Bloomberg", "Microsoft", "Uber", "Google", "IBM", "Netflix"]. -
Task 1: Used
.shift()to remove the first company from the array. -
Task 2: Used
.splice()to remove "Uber" and add "Ola" in its exact location. -
Task 3: Used
.push()to add "Amazon" to the end of the array dynamically.
Successfully executing multiple operations on a single dataset and tracking how the indexes changed felt like writing true administrative frontend logic!
๐ฏ My Goal for Tomorrow (Day 15 / Lecture 5)
Tomorrow, I will be moving to Lecture 5 of the Apna College sequence:
- Stepping into Functions and Methods in JavaScript.
- Learning how to block reusable code together and understanding parameters, arguments, and return types.
๐ฌ Let's Connect!
To the Apna College alumni: How clean did you write your solution for the Companies challenge? To seniors: Do you use .splice() often in production, or do you prefer non-mutating modern methods?
My completed array manipulation scripts are pushed to GitHub!
[Links in the Comments]
Two weeks down, a lifetime of engineering to build. Keep moving forward! ๐