Insha Profile picture
All things content + community 🥑 | Web3 x AI 🛠️ | @shefiorg S11 | Prev- @ShowwcaseHQ| DM for Collab 📩

Sep 1, 2021, 17 tweets

Hey there JavaScript Developers 👋

Let's learn about some important Array Methods 😎👇

A little introduction about Arrays:

To store ordered collections, there exists a special data structure named Array in JavaScript.

Array elements are numbered, starting with zero. And it can store elements of any type.

Some of the Array Methods 👇

1️⃣ push()

The push() method adds a new element at the end of an array.

2️⃣ pop()

The pop() method extracts the last element of the array and returns it.

3️⃣ shift()

The shift() method removes the first array element and shifts all other elements to a lower index and returns the value that was shifted out.

4️⃣ unshift()

This method adds the element to the beginning of the array.

5️⃣ splice()

The arr.splice method can be used to: insert, remove and replace elements.

The splice() method takes in:

start - The index from where the array is changed.
deleteCount (optional) - The number of items to remove from the start.
item1, ..., itemN - inserts elem1, ..., elemN at their place. If not specified, it'll only remove elements from the array.

6️⃣ concat()

The concat() method returns a new array by merging two or more values/arrays.

7️⃣ slice()

It returns a new array copying to it all items from index start to end (not including end)

8️⃣ sort()

The sort() method sorts the items of an array in a specific order (ascending or descending).

9️⃣ join()

The join() method returns a new string by concatenating all of the elements in an array, separated by a specified separator.

🔟 filter()

The filter() method returns a new array with all elements that pass the test defined by the given function.

Remeber filter() does not change the original array.

1️⃣1️⃣ reduce()

This method calculates a single value over the array by calling function for each element and passing an intermediate result between the calls.

Remember that calling reduce() on an empty array without initialValue will throw TypeError.

1️⃣2️⃣ map()

The map() method creates a new array with the results of calling a function for every array element.

There are plenty of Array methods in the JavaScript language. Some of them are used rarely while some of the above-mentioned methods are commonly used.
If you learned something make sure to retweet the first one. 😊🙌

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling