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

127
Vistas
Having issues trying to destructure array to new variables for assignment

I am working on a project and am encountering an obstacle on something rather small. I am trying to take an array that has a string and a nested array. Remove the string assigning it to a new variable and then destructure the nested array into two new variables. I seem to be having problems as there is an undefined placeholder and I can't seem to find a way to get around it. I think I must be messing something up simple, but I would appreciate it if you could help me understand my mistake. Any help would be great.

Here is the code which I can't seem to get working.

let operandArray = ['x', [1, 1]]
let temporaryArray = [];

const operator = operandArray.shift();

temporaryArray = operandArray[0];
console.log(temporaryArray);

let [operand1, operand2] = [...operandArray];
console.log(operandArray);
console.log(operand1, operand2)
.as-console-wrapper { max-height: 100% !important; }

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can simply use this.

const operandArray = ['x', [1, 1]]
const [str, [x, y]] = operandArray;
console.log(str, x, y);

You may wanna have a look at this blog post for a more detailed explanation of the desctructuring syntax.

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