Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!