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
Uberduck.AI is a tool that allows you to make any text sound like it's been read by a celebrity or fictional character, and the results are incredible.
Check out these 10 amazing Dev Resources for youππ
1οΈβ£ Repl
Replit is a simple yet powerful online IDE, Editor, Compiler, Interpreter, and REPL. You can code right in your browser.
The second you create a new repl, it's instantly live and sharable with the world.
DevDocs combines multiple API documentations in a fast, organized, and searchable interface. Here you can find multiple developer documentation in a clean and organized web UI with instant search, offline support.
Here are 5 Awesome APIs for your next project π
APIs let your product or service communicate with other products and services without having to know how theyβre implemented. This can simplify app development, saving time and money. When youβre designing new tools and products or managing existing onesβAPIs give you flexibility
1οΈβ£ The NASA APIs
NASA offers a bunch of useful APIs for application developers. The objective of this site is to make NASA data, including imagery, eminently accessible to application developers.
If yes, then you must know about JavaScript Set Objects.
Let's discuss it in detail π
What is a Set?
A Set is a collection of unique values. That means the set can never have any duplicates and can hold any values of any data type. You can iterate through the elements of a set in insertion order.
Okay, this sounds interesting. So the question is how to create a set ?
To create a set we write- new Set() and in the parentheses, we need to pass an iterable.
5 Awesome Websites you won't believe exist. πβ‘
A Thread π
1οΈβ£ CodeElf
If you encounter difficulty in naming the variables then this is perfect for you. With CodeElf you can search over GitHub, Bitbucket, GitLab to find real-world usage variable names.