DEV Community

Akash P
Akash P

Posted on

# of ways to loop Array in JavaScipt

Hello, World!
Here is a challenge, tell me the no of ways in which we can loop over the given arrays below?

//Array one

let letters = ['j','a','v','a','s','c','r','i','p','t']

//Array Two

let javaScipt = [
 {
   name:'Angular',
   by:'Google'
 },
 {
   name:'React',
   by:'Facebook'
 },
 {
   name:'Vue',
   by:'Evan'
 }
]
Enter fullscreen mode Exit fullscreen mode

Top comments (6)

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀 • Edited

Alright let's give this a shot.

  • Recursion
  • .forEach
  • .map
  • .every
  • .some
  • .flat
  • ... You get the point, mostly all of the array methods loop under the hood
  • For loop (of)
  • For loop number or length based
  • (cheating here) labeled for loop
  • while loop
  • do while
  • setInterval
  • generator
  • itterator
  • pass to Wasm
  • aws lambda posted
  • manually typing array[n]
  • deprecated! For each in

Any more for anymore anyone?

Collapse
 
akashpreet profile image
Akash P

.filter

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

"You get the point, mostly all of the array methods loop under the hood"

That covers filter and find

Collapse
 
akashpreet profile image
Akash P

One of the resourse I found in #devcommunity by @florinpop17
dev.to/florinpop17/24-javascript-a...

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀 • Edited

Unfortunately this sort of artical goes out of date quite quickly. Missing Array.prototype.flatMap()

Always best to Google.

Thread Thread
 
akashpreet profile image
Akash P

Fact (PERIOD).