0
var obj={"student":[{"id":1,"name":"mark"}]}

For example I have this object I want to add another element to it such as this:

var teacher=  "teacher":[{"id":1,"name":"Stacy"}] 

to make this new object:

var objnew= {"student":[{"id":1,"name":"mark"}], "teacher":[{"id":1,"name":"Stacy"}] }
0stone0
  • 34,288
  • 4
  • 39
  • 64
A_S_999
  • 1
  • 2

1 Answers1

0

You can use this code.

var objnew = Object.assign({}, obj, teacher);
  • You should maybe add some code to explain what you mean, or link to some [online documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign). At the moment this answer is rather sparse. – Andy Sep 06 '22 at 12:48