Ted
Ted

Reputation: 1760

extract object inside other object

I have next code:

let otherObject = {stat: 1, pos: 3, ..... other parameters};

function someF() {
    return {
      valid: false,
      otherObject,
    };
}

this function return next object:

{
   valid: false,
   otherObject
}

but what I need is to get parameter of otherObject:

{
   valid: false,
   stat: 1,
   pos: 3,
   .....
}

Upvotes: 2

Views: 60

Answers (1)

Majed Badawi
Majed Badawi

Reputation: 28414

You can use the spread operator:

let otherObject = {stat: 1, pos: 3};

function someF() {
    return {
     ...otherObject,
     valid: false,
    };
}

console.log( someF() );

Upvotes: 1

Related Questions