Did you try just using 1 instead of "1"?
Problem with javascript ( Array is automatically converted to string )
Hello all : )
I have a very strange problem...
so I have an object like this:
{
"1": [ {...}, {...} ],
"2": [ {...}, {...}, {...} ]
}
and so on. these keys are IDS. so I want to get the current array with ID
const getFirstArray = myObjectWithArrays[ID]
so if ID is 1 it will return the first array of objects. and it's working well. but the next step is that I need to generate an excel file with this data. Am using the XLSX library to generate an excel file.
XLSX.utils.json_to_sheet(data)
in data, u must add an array of objects. it's working with other arrays but when I am adding an array like this myObjectWithArrays[ID] Am getting error "carr[1].forEach is not a function" I searched and found info that
"using numbers as property names in JavaScript objects can sometimes cause unexpected behavior since they can be automatically converted to strings."
I really need to fix this problem... Please can anyone help me with this?
Please or to participate in this conversation.