I have a function that loops through an object.
I want data on the form
group1:Array[1,2,3]
group2:Array[4,5,6]
group2:Array[7,8,9]
But instead I get the data on the form
group1:Array[1,2,3,4,5,6,7,8,9]
group2:Array[1,2,3,4,5,6,7,8,9]
group2:Array[1,2,3,4,5,6,7,8,9]
That is it copies the values in the first group that I loop through and then add those values to the rest of the groups and I don't want that. It gets wrong in the function call
for (var resultGroupElement in value[resultKey].DCTRecord.DCT[resultGroup])
And I don't know how to fix it. Do you guys perhapse know how to fix it? I have tried to delete the variables without any luck.
Thanks in advance.
getData: function(value) {
var dataArray = [];
var dataArrayHolder = [];
for (var resultKey in value) {
var stopTimeConverted = $.extend(true, {}, convertDateToWorkWithAllBrowsers(value[resultKey].StopTime));
var resultGroups = value[resultKey].DCTRecord.DCT;
for (var resultGroup in resultGroups) {
for (var resultGroupElement in value[resultKey].DCTRecord.DCT[resultGroup]) {//Here is where its going wrong
if (dataArray[resultGroupElement] != null) {
var curResultGroupDCT = dataArray[resultGroupElement];
}
else {
var curResultGroupDCT = [];
}
curResultGroupDCT.push(
[
new Date(stopTimeConverted),
11
]
);
dataArray[resultGroupElement] = curResultGroupDCT;
delete curResultGroupDCT;
}
dataArrayHolder[resultGroup] = dataArray;
delete dataArray;
}
}
console.log(dataArrayHolder);
}