Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda