Introduction to Array.prototype of JavaScript

Learn about Array.prototype
of JavaScript.
Overview
I forgot how to use JavaScript's Array.prototype
methods, so i'll re-learn it.
Fortunately, MDN is kind enough to explain Array.prototype
.
Array.prototype.concat()
Example:
Code:
|
|
Result:
|
|
Array.prototype.every()
The every()
returns true if all elements in the array passed the condition, and false otherwise.
Example:
Code:
|
|
Result:
|
|
Array.prototype.filter()
The filter()
returns new array which contain elements
that passed the condition in the array.
If it passed none, return an empty array otherwise.
Example:
Code:
|
|
Result:
|
|
Array.prototype.find()
The find()
returns the first element that matches the condition.
If matched element is nothing, it returns undefined
.
Example:
Code:
|
|
Result:
|
|
Array.prototype.flat()
Example:
Code:
|
|
Result:
|
|
Array.prototype.flatMap()
Example:
Code:
|
|
Result:
|
|
Array.prototype.forEach()
Example 1:
Code:
|
|
Result:
|
|
Example 2:
Array.prototype.forEach()
provide index
.
Code:
|
|
Result:
|
|
Example 3:
Array.prototype.forEach()
skip uninitialized value in array.
Code:
|
|
Result:
|
|
So, skip index of uninitialized value.
Code:
|
|
Result:
|
|
Example 4:
Array.prototype.forEach()
doesn't support break
and continue
.
Code:
|
|
Result:
|
|
Array.prototype.includes()
Example:
Code:
|
|
Result:
|
|
Array.prototype.indexOf()
Example:
Code:
|
|
Result:
|
|
Array.prototype.join()
Example:
Code:
|
|
Result:
|
|
Array.prototype.map()
Example:
Code:
|
|
Result:
|
|
Array.prototype.pop()
The pop()
removes the last element of the array. Then, it returns the deleted element.
Also, the array is changed by the method.
Example:
Code:
|
|
Result:
|
|
Array.prototype.push()
Example:
Code:
|
|
Result:
|
|
Array.prototype.some()
Example:
Code:
|
|
Result:
|
|
Conclusion
mumumu……
I have no confidence to keep up skill of JavaScript…