The question itself is probably in need of editing but hear me out pls. I have this:
[
["a","b","c"],
["apple", "orange", "banana"],
["kiwi", "tomato", "avocado"],
["beans", "asparagus", "spinach"]
]
I need it so that it will look like the one below:
[
{"a":"apple", "b":"orange", "c":"banana"},
{"a":"kiwi", "b":"tomato", "c":"avocado"},
{"a":"a", "b":"asparagus", "c":"spinach"}
]
I have done something like this:
const rows = [
["a","b","c"],
["apple", "orange", "banana"],
["kiwi", "tomato", "avocado"],
["beans", "asparagus", "spinach"]
]
const dataObj = {};
const dataArr = [];
if (rows.length) {
keys = rows[0];
values = rows[0];
rows.forEach((element, i) => {
values = rows[i];
keys.forEach((key, j) => {
dataObj[key] = values[j];
dataArr.push(dataObj);
});
});
}
To no avail and got something like this:
[
{"a":"apple", "b":"orange", "c":"banana"},
{"a":"apple", "b":"orange", "c":"banana"},
{"a":"apple", "b":"orange", "c":"banana"}
]
This is not the desired output. If you can help me out - and our community! - it would be super. Thanks!