Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

140
Visualizações
How can I use destructering in JavaScript with dataset property?

I want to assign two variables with destructering. My current attempt looks like this:

const { textContent, dataset.value: dataValue } = dropDown;

dropDown is a DIV node with an data-attribute(value) and inner text.

This obviously didn't work out, I got the error message Uncaught SyntaxError: missing : after property id. Because of this, I changed the code like this:

const { textContent, dataset: dataValue } = dropDown;

This did work better, textContent was successfully declared with the correct variable. However, I want that the variable dataValue gets assigned with the content of the data-attribute(dataset.value) of the DIV node. After running my above code, I also found out that the dataset property contains a DOMStringMap.

This is the result, the code outputs: { "textContent": "Select", "dataValue": { "value": "none" } }

How am I able to assign the content of the dataset.value to the variable dataValue directly with destructering?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Nested objects can be destructured like this,

const object = { "textContent": "Select", "dataset": { "value": "none" } };

let {textContent, dataset: {value: dataValue }} = object;
console.log(dataValue);

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda