ARRAY ITERATOR METHODS.
WHAT IS ARRAY ITERATOR?.... An array is a single variable that is used to store different elements.
Array iteration-This is used to traverse an array and dynamically access elements of that array.
- it operates on every array item.
- accessing each element of array one by one.
Examples of iteration methods ….. forEach(),filter(),map(),reduce(),reduceRight,every(),some(),and find().
ForEach()
To -do -list. 1.define forEach 2.how is forEach array used ….its advantages and disadvantages . 3.syntax of forEach(). 4.example of for each arrays in code examples.
DEFINE forEach()
Output
Advantages.
- It eliminates the possibility of bugs
- makes the code more readable.
- It is known as the for-each loop since it traverses each element one by one.
##Disadvantages
- It is generic…this is because the call back function we pass to it can contain whatever functionality we like .
- It is slower to execute compared to for()
The forEach method requires three parameters, one for the current element’s value, the second parameter for the current element’s index, and the final one is for the array upon which the forEach() method has to work.
SYNTAX
##Maps
The map() method creates a new array populated with the results of calling a provides function on every element in the calling array
MAP syntax
using value and index
Using array
##find
The find method returns the is element in the provided array that satisfies the provided testing function if no value satisfies the testing function undefined is returneds
Find Example
Find Syntax
Resources linuxhint.com/array-iteration-methods-javas.. w3schools.com/js/js_array_iteration.asp developer.mozilla.org/en-US/docs/Web/JavaSc..
Happy Coding