N
N
Ninja Mate2016-08-11 01:02:20
JavaScript
Ninja Mate, 2016-08-11 01:02:20

How to properly join Object?

There are two objects that need to be combined into one.

(string)=>{
    var subDocString = that.state.subDocString;
    var assignSubDocString = {subDocString, string};
    //записали в новую переменную старое или пустое значение,
   // создали новый обьект и записали оба                                               
 that.setState({ subDocString: assignSubDocString});
}

assignSubDocString == {"subDocString":{"stack": ....}, "string":{"stack": ....}}

it goes like this, but it needs to
assignSubDocString == {{"stack": ....}, {"stack": ....}}

How to do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Izmailov, 2016-08-11
@victorzadorozhnyy

And so you will not succeed, the elements of the object require a key. Use arrays [{},{}]

A
Alexander Medvedev, 2016-08-11
@lifestar

Come on like this

var assignSubDocString = Object.assign(subDocString, string);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question