JavaScript Array Iteration

JavaScript Array Iteration


JavaScript Array Iteration
In this tutorial, you will learn about JavaScript Array Iteration is as follows:
JavaScript  Array.foreach()
With help of foreach(), we can access array elements iteratively in JavaScript.
Example
Output

JavaScript Array.map()

The map() method creates a new array with the results of calling a provided function on each element in the calling array.

Syntax

var new_array =

current_array.map(function(currentItem, index, array)

{

      //Application Logic to current array items 

         //return items for new array

})

Example1

https://lh6.googleusercontent.com/koOZHNu5iOXaqFdwojJDUIm7n8hhiFi95REbEtaOVlIGZIuJ9y5SGAxiRBaJnauNoP_X0QxBIAwaWtMOpetVCZA88T6t7QqtDBfUEEz96a-hMjdywjIqm4JdQEUgcNbTH2v9bXFo

Output

https://lh5.googleusercontent.com/Cx7Rq6LDb0RaRbEInQxMX2PzB8TEXj10kmCDqVyNxGVMBGv0wraJyiLgylsyTdfYItuzIgrvRNRhxs7twKL3fDVnt2zSrU1rJNjld9B_xZW3SgfNgLTtpxle4HnHCfcmOGyuHKIX

Exaple2- Mapping an array of numList to an array of square roots

https://lh5.googleusercontent.com/g3MSdoaVNDOA9xvcFF_sfPaFWLFIFwZw74q_aoxMNzi5grGVIj1xpO33M9mJX31sLDf7c10rDBRFRRZXekUKT9mrGpNa5lCwCdtHOr-aAcOgO1esX03UC2mLWyV-qdRghM9xb4lG

Output

https://lh6.googleusercontent.com/ALBaYFr9beH1EHPgUuhKnORfMXt4NJqwWYMWl5lnfCpT0ZUjSk9McsQtBjaVM9B9_DOIOJQuWVOW4J9ysm_Rroc-4Jf27z8FMCE_yWQqbQYMcpuBEiHOITTO0nM8bKnWoyYXeLSG

JavaScript Array.filter()

In this tutorial, you will learn about Array filter() for filtering of array element with help of examples:

Example1

Output

Example

Output