0

I have a javascript Object obj with the fields:

{ key1: val1,
  key2: val2,
  key3: 
       [{subkey1: subval1,
         subkey2: subval2 },
        {subkey3: subval3,
         subkey4: subval4 }],
  key4: val4
}

Now if I add a key value pair to this object,

obj.key5 = val5;

and print the obj Object (by console.log(obj) ), it doesn't show the key5: val5 pair.

However, doing console.log(obj.key5) does output val5, so the key value pair is being added.

Why doesn't it show on print the whole object?

I even tried creating a duplicate object and assigning key5 to the new one, but it behaves similar to the original object.

I tried using Object.assign() to give the same results as above.

I need to pass the obj Object as an argument to another API, and even though obj.key5 exists, on passing it as an argument, the API doesn't read `key5'.

Thank you.

deathstroke
  • 526
  • 12
  • 33

1 Answers1

0

On printing the object (i.e. console.log(obj) ), it doesn't show me the {key5:val5} pair.

But if I do console.log(obj.key5), it does show me val5.

Maybe it is something to do with asynchronous execution of statements in node.js, where console.log(obj) is executed before the obj.key5 = val5 assignment?

deathstroke
  • 526
  • 12
  • 33