Is it possible to disrupt an object inside another object?

Asked

Viewed 166 times

0

inserir a descrição da imagem aqui

I know it’s possible to do this with arrays, type one array thus

const array = [[['teste']]]
const [[[variavel]]] = array
variavel // => 'teste'
  • there is some way to do something similar to objects?

  • without declaring their key?

    const {teste1:{teste2:{teste3}}} = obj test 3 // => 'hi'

only in such a case {{{teste3}}}?

  • this object is in invalid format, because every object has the key and value feature

1 answer

1


By characteristic every object in has chave and valor and in the example quoted in your question the format is invalid.

The valid format is:

const c = {teste1:{teste2:{teste3:1}}}

and its dismantling:

const {teste1:{teste2:{teste3}}} = c;
console.log(teste3);

and so works perfectly.

Functional example:

const c = {teste1:{teste2:{teste3:1}}}
const {teste1:{teste2:{teste3}}} = c;
console.log(teste3);

  • 1

    got it, thanks for the quick reply, I thought it was possible to equal an array without declaring these hehe keys, more thank you even

Browser other questions tagged

You are not signed in. Login or sign up in order to post.