let arr = [{
question:{
q1 : 123,
q2 : 44
}
}];
I've tried using forEach loop to do it, but it returns nothing.
let arr = [{
question:{
q1 : 123,
q2 : 44
}
}];
I've tried using forEach loop to do it, but it returns nothing.
If it's an array then you can do either map
or forEach
.
arr.forEach()
However you have to pay attention to the internal structure of the item as well, ex. in your case
arr.forEach(item => {
console.log(item.question.q1)
})
And if you want the transformation, then
const transformedArr = arr.map(item => item.question.q1)