Someone is sitting in the shade today because someone planted a tree a long time ago.
The question is, how do I know which array methods are popular or not? I was able to do that through a tool called Google Trends.
Google Trends is a website created by Google that analyzes the popularity of top search queries in Google Search across various regions and languages. The website uses graphs to compare the search volume of different queries over time.
Analysis of the query results from the image above shows that, Array.prototype.entries() is not as used compared to other array methods like map, filter and reduce
From our result, using the array.entries() method, we were able to get the key value pair for each index of the array.
The query result shows that the Array.prototype.copyWithin() method shows that the data for amount of time it's been queried is insufficient to be plotted into a graph, which is why it's on this list.
4 5 6 4 5 6 7 8 9 10
our result above shows that the copyWithin method placed at position 0, the index between 3 and 6, while the length of our array remains the same.
The every() method checks if all the elements in an array meets up with the condition provided by a specific function.
This method returns a Boolean value depending on the condition set by a particular function.
The graph above shows that the query results of Array.prototype.every() is not as used compared to other array methods like map, filter and reduce which is why it's on this list.
The example above checks if all the numbers in the figure array are either equals to, or greater than 18, which is why it returned the Boolean value true
The Array.fill() method is used to fill the elements in an array with a given static value. It takes in three parameters, the value which is required and start and end which are both optional.
The start and end parameters helps us to specify which position to fill in the array.
Array [1, 5, 5, 5, 5, 5, 5]
Array [6, 6, 6, 6, 6, 6, 6]
The first console.log() specifies two parameters, which is that the entire array should be filled with the number 5 from the index position of 1.
The second console.log() fills the entire array with the number 6, because there was no start or end parameter specified.
The isArray() method helps to primarily check if an object is actually an array. It returns a Boolean value, that is, true if an object is an array and false if it's otherwise.
Nothing to explain here really, it's obvious from the code above that the first example is an array while the others are not arrays. Hence the reason we got our results as Boolean(true, false, false).
The keys() method helps to return a new Array Iterator Object containing the keys for each position of index in an array.
We created an array of countries and then we called the keys() method. Looping through each key we were able to get an index for each member of the array.
The lastIndexOf() method searches through an array for a specified item and then return it's position.
The array is searched backwards, if no position is specified. If the given element is not found, it returns an index of -1.
It can take two parameters (array.lastIndexOf(item, start)), item and start.
The result of the first console.log(); returned o because, we used the start parameter to specify the count to start from the second item of the array.
The reduceRight()method reduces the length of an array to a single value.
The method applies a function against an accumulator and each value of the array from right to left.
The numbers in our array are subtracted from the right, giving us the value -500 in the process.
The reverse() method simply reverses the order of an array. That is, the first item of an array becomes the last and vice versa.
It is worthy to note that this method will also change the order of the original array.
Using the reverse() method, we were able to reverse the order of the elements in the array.
This method returns the original array without modifying it in any way.
It is the default method of an array object.
To get more free content on web development, subscribe to my newsletter: