In this code, I am getting a value 34 in the newArr. Which is expected and correct.
var arr = [1, 2, 34, 5, 6, 67, 4]
var val = 34
var newArr = []
arr.forEach((elm) => {
if (val == elm)
newArr.push(elm)
})
console.log(newArr)
But when I am using async await
I am not getting any value in newArr.
var arr = [1, 2, 34, 5, 6, 67, 4]
var val = 34
var newArr = []
arr.forEach(async(elm) => {
await setTimeout(function() {}, 10);
if (val == elm)
newArr.push(elm)
})
console.log(newArr)
I am new to Javascript and not able to understand why this is not working as I am expecting.