Why I can't loop on 'data' ?
data = [{type: 'a', data: 'xyz'}, {type: 'a', data: 'xyz'}, {type: 'a', data: 'xyz'}];
for (i in data) {
console.log('one line');
}
0 results, but data[0], data1, data[2] has data...
Why I can't loop on 'data' ?
data = [{type: 'a', data: 'xyz'}, {type: 'a', data: 'xyz'}, {type: 'a', data: 'xyz'}];
for (i in data) {
console.log('one line');
}
0 results, but data[0], data1, data[2] has data...
You can definitely loop any kind of array in javascript I'll only provide one way to loop and I believe it is the most easier one for beginners:
const data = [{},{},{}]
data.map((object)=>console.log(object)) // object would be each object of your data array.
try using for of
for (i of data) {
console.log(i);
}
output:
{ type: 'a', data: 'xyz' }
{ type: 'a', data: 'xyz' }
{ type: 'a', data: 'xyz' }