Linked Questions

177 votes
2 answers
98k views

Also, is this a style question or a functional question? Is it a matter of preference or is one better? I'm trying to understand the purpose of for-of. Usually I use, let iterable = [10, 20, ...
user avatar
3343 votes
35 answers
2.5m views

Are there any issues with using async/await in a forEach loop? I'm trying to loop through an array of files and await on the contents of each file. import fs from 'fs-promise' async function ...
Saad's user avatar
  • 54.7k
2244 votes
32 answers
1.9m views

[1,2,3].forEach(function(el) { if(el === 1) break; }); How can I do this using the new forEach method in JavaScript? I've tried return;, return false; and break. break crashes and return does ...
Scott Klarenbach's user avatar
43 votes
8 answers
22k views

I am trying to convert this array let orders = [ { amount: '100', user: 'admin', date: 'March 6, 2019' }, { amount: '120', user: 'admin', date: 'March 6, 2019' }, { amount: '80', user: '...
photosunthesis's user avatar
26 votes
5 answers
10k views

This code generates an error: function *giveNumbers() { [1, 2, 3].forEach(function(item) { yield item; }) } This is probably because yield is inside a function that is not a generator....
Dima Slivin's user avatar
4 votes
6 answers
28k views

I got data where in an array I got set of objects (with country and states keys along with values). Now, I need to format data in such a manner, that I got a new array (with countryName as key, and ...
Deadpool's user avatar
  • 8,296
5 votes
2 answers
3k views

Say I have: const m = new Map(); is there a performance difference between: for(let v of m){ } vs. m.forEach(v => {}); I assume Map.protoype.forEach uses an iterator just like for..of? I read ...
user avatar
-3 votes
3 answers
174 views

so I've wrote this function, i want to uppercase the vowels and lowercase every other letter, problem the end result ends with the same string, I'm new to spread and for-each, after i spread a string ...
user avatar
1 vote
1 answer
74 views

I'm trying to understand callbacks thoroughly and this is the fundamental missing piece. I've scoured the internet for this answer but most just talk about async callbacks. Q 1: Why do some built-in ...
jgrewal's user avatar
  • 189
1 vote
1 answer
153 views

I have found a way to copy the entries from one Map to another Map where the target Map has multiple reference variables but I suspect it is not optimal. Is there a shorter/more efficient way? const ...
user2309803's user avatar
0 votes
0 answers
42 views

So I'm working on a FreeCodeCamp javascript problem. I was able to write a working function using a for loop, but when I try to write the same function with a forEach loop, it doesn't work. How can I ...
K Strong's user avatar