Chandana
Chandana

Reputation: 125

Why an additional array of arrays create inside the JSON object array in javascript

I add JSON objects to an array using push command. After adding that array shows only two JSON objects. Then I add the whole array to another array that contains 7 other arrays. Finally, when I access the JSON object array it shows two JSON objects and one additional array that contain same objects and the array. Here I attached the code and result of the outcome. How can I resolve this?

prevArrhythBeats.push(
  {
      x: annotationPacket[k].timestamp,
      title: annotationPacket[k].annotBeat.a_type,
      text: annotationPacket[k].annotBeat.a_desc
  }
);

dataFactory.setPrevData(prevChOne, prevChTwo, prevGrid, prevLeadChange, prevMotion, prevArrhythBeats)

dataFactory.setPrevData = function (cOne, cTwo, grid, lead, mot, beat) {
                prevData.push(cOne);
                prevData.push(cTwo);
                prevData.push(grid);
                prevData.push(lead);
                prevData.push(mot);
                prevData.push(beat);
}

before add to dataFactory.setPrevData enter image description here

After dataFactory.setPrevData method enter image description here

Upvotes: 3

Views: 53

Answers (1)

Burak Akyıldız
Burak Akyıldız

Reputation: 1644

You are pushing array to itself.

Upvotes: 2

Related Questions