I am trying to add objects formatted as {title: value} to an array. I wrote the following function
const newResults = resultData.map(result => {
let results = [];
if (result.INTELLCONT.length > 1) {
for (let i = 0; i < result.INTELLCONT.length; i++) {
results.push({
title: result.INTELLCONT[i].TITLE._text,
});
}
} else {
results.push({
title: result.INTELLCONT.TITLE._text,
});
}
return results;
});
But the array being returned looks like this
[Array(3), Array(1), Array(4), Array(1), Array(2), Array(1), Array(4)]
I want it to look like this
[{title: value}, {title: value}, {title: value}, {title: value}, {title: value}, ... ]
What am I doing wrong?
.map().flat().result.INTELLCONT.TITLE._textis accurate? Because it seems likeresult.INTELLCONTis an array and you'd need to change that toresult.INTELLCONT[0].TITLE._text.