Itnerators
Notice the different methods being called on the arrays:
.forEach()
will execute the same code for each element of an array but does not change the array and returnsundefined
.
.map()
takes an argument of a callback function and returns a new array.
- .filter() returns an array of elements after filtering out certain elements from the original array.
.findIndex()
on an array will return the index of the first element that evaluates totrue
in the callback function. It returns-1
if none of the elements in the array satisfies the condition.
EX:
.reduce()
method returns a single value after iterating through the elements of an array, thereby reducing the array. EX:
- The
some()
method tests whether at least one element in the array passes the test implemented by the provided function.
EX:
Prints: True
- The
filter()
method creates a new array with all elements that pass the test implemented by the provided function.
EX:
- The
every()
method tests whether all elements in the array pass the test implemented by the provided function.
EX:
Prints: True
- The .reduce( ) take an array that contains multiple values and returns a single value.
What did I learn?
I learned about a few more methods to test the elements to see if it passes or not. And I also found another website that teaches about coding, the https://developer.mozilla.org/en-US/ it has everything that a developer might need.
What I'll be doing tomorrow?
OBJECTS in javaScript
No comments:
Post a Comment