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. ππ
β’ β’ β’
Missing some Tweet in this thread? You can try to
force a refresh
10 repositories that will transform the way you approach technical interviews.
A Thread ππ»
1. Coding University Interview
A complete computer science study plan to become a software engineer. This GitHub repo will take you from ground level to advanced concepts in a systematic manner.
This repository has practical content that covers all phases of a technical interview, from applying for a job to passing the interviews to offer negotiation.
Wordtune is an AI-powered writing tool that understands what youβre trying to say and suggests ways to make your writing clearer, more compelling, and authentic.