Thursday, April 25, 2019

JavaScript(9)---Iterators

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 returns undefined.

EX: 

Print:
I want to eat mango
I want to eat papaya
I want to eat pineapple
I want to eat apple
  • .map()takes an argument of a callback function and returns a new array.
EX:

Print:
HelloWorld
[ 1, 2, 3, 4, 5]
  • .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 to true 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: 
Prints: 
  • 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