0

let's jump to the problem

// lets say i have a simple array of objects inside an object

const abc = {
  a: 1,
  b: [{aa: 1, bb: 2}, {aa: 2, bb: 2}]
}

// then I want to update the array with push a new object

abc.b.push({aa: 3, bb: 3})

But why it is resulting

{
  a: 1,
  b: [[Object], [Object], [Object]]
}

I expecting the result

{
  a: 1,
  b: [{aa: 1, bb: 2}, {aa: 2, bb: 2}, {aa: 3, bb: 3}]
}

The result I got with nodejs console.log(abc)

asrofil
  • 25
  • 4

1 Answers1

1

const abc = {
  a: 1,
  b: [{aa: 1, bb: 2}, {aa: 2, bb: 2}]
}

// then I want to update the array with push a new object

abc.b.push({aa: 3, bb: 3})
console.log(JSON.stringify(abc))
Wang Liang
  • 4,244
  • 6
  • 22
  • 45