I came across an error today, and I am not sure why it occurred. At the second for loop, the access to data will be undefined instead of the data that was inserted as a parameter into the function. Somehow the data gets the value of null, instead of the Object that was passed to this function. Does anyone know why? The error I get is "data is not defined".
createDataObject: function (data) {
let dataObj = data.source[0];
let backedData = data.backedData;
for (let i in dataObj) {
let d = dataObj[i];
d.data = { source: d.data };
}
for (let i = 0; i < data.backedData.length; i++) {
let bd = data.backedData[i]; //<- this is where the error occurrs
let data = bd.data[0];
}
}
Here is some code outside of the object, if you want to try, that I was using, this will work on your console or in node. Seems like I have come across a Javascript compiler bug. I am not sure.
createDataObject({source: [[{data: 1}]], backedData: [1,2,3, 4]});
The code above will work if I do the following
createDataObject: function (data) {
let dataObj = data.source[0];
let backedData = data.backedData; //create the backedData variable here
for (let i in dataObj) {
let d = dataObj[i];
d.data = { source: d.data };
}
for (let i = 0; i < backedData.length; i++) {
let bd = backedData[i]; // no Error
let data = bd.data[0];
//.....
}
}