-3

so lets say i have this objects:

{
"8282748274" : "melly",
"2764726482" : "john",
"8268274827" : "carol"
}

how do i add new data to it so it would look like this:

{
"8282748274" : "melly",
"2764726482" : "john",
"8268274827" : "carol",
"0000000000" : "NewDataHere",
"0000000001" : "MoreNewData",
etc
}

i tried using object.push but it didn't work, here's the code i tried to use

let newData = {
  "385835638578" : "alex",
  };
  
object.push(newData); 

how do i solve this?

1 Answers1

0

Objects do not have a push method. They are not arrays.

In this case, you can use Object.assign:

const obj = {
  "8282748274": "melly",
  "2764726482": "john",
  "8268274827": "carol",
}

let newData = {
  "385835638578": "alex",
};

Object.assign(obj, newData)

console.log(obj)
Spectric
  • 30,714
  • 6
  • 20
  • 43