I'm parsing a json file and at this point have gathered up data from a spreadsheet. Can anyone tell me why when I set an array like this
function getfaq()
{
fetch(faq, settings)
.then(res => res.json())
.then((json) => {
for(var i = 5;i<json.feed.entry.length;i++)
{
col = json.feed.entry[i].gs$cell.col
faqdata[i-5] = [];
if(col == 1) {
faqdata[i-5][0] = "Question:"
faqdata[i-5][1] = json.feed.entry[i].gs$cell.inputValue
} else if(col == 2)
{
faqdata[i-5][0] = "Answer:"
if(json.feed.entry[i].gs$cell.inputvalue != "")
{
faqdata[i-5][1] = json.feed.entry[i].gs$cell.inputValue
} else {
faqdata[i-5][1] = "N/A"
}
} else if(col == 3)
{
faqdata[i-5][0] = "Command:"
faqdata[i-5][1] = json.feed.entry[i].gs$cell.inputValue
} else if(col == 4)
{
faqdata[i-5][0] = "Image:"
faqdata[i-5][1] = json.feed.entry[i].gs$cell.inputValue
} else if(col == 5)
{
faqdata[i-5][0] = "Reference:"
faqdata[i-5][1] = json.feed.entry[i].gs$cell.inputValue
}
}
for(var j = 0;j<faqdata.length;j++)
{
if(faqdata[j][0].includes("Command:"))
{
faqC[j] = faqdata[j][1]
console.log(faqdata[j][1]);
}
}
})
}
my output looks like this
[
<1 empty item>, 'reset',
<2 empty items>, 'justmaxed',
<2 empty items>, 'ascended',
<1 empty item>, 'masteries',
<1 empty item>, 'gliding',
<1 empty item>, 'mounts',
<2 empty items>, 'livingworld',
<2 empty items>, 'gold',
<2 empty items>, 'dungeons',
<3 empty items>, 'fractals',
<1 empty item>, 'raid'
]
when I just throw a log into it my output looks like
reset
justmaxed
ascended
masteries
gliding
mounts
livingworld
gold
dungeons
fractals
raid
I don't understand why it's adding in when I try to import it into an array but when I log the data it displays correctly. I have tried my best to figure it out but I do not know why its adding into the array like this...
faqdatadon't satisfy your condition. Yet, when they do, you're pushing to a specific index (j) that has incremented regardless. TryfaqC.push(faqdata[j][1])instead