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

161
Visualizações
Why does putting a variable in angle brackets access the first value of an array

I've been using this trick a few time now but I still can't wrap my head around why this works and can't seem to find the answer. Could anybody please explain ?

let myArray = [0, 1]
let [myVar] = myArray
console.log(myVar) // outputs 0

How is [myVar] the same thing as putting [0] behind myrArray ?

Edit: already asked and answered here : Multiple assignment in javascript? What does [a,b,c] = [1, 2, 3]; mean?

Thank you everyone

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

0

You are probably looking for this reference.

But basically, the brackets can be used to assign individual elements of a structure/array to variables, and it can be used with more than one, as well.

E.g.:

let myArray = [0, 1]
let [myVar1, myVar2] = myArray
console.log(myVar1) // outputs 0
console.log(myVar2) // outputs 1

PS: fyi these [] are square brackets, and these <> are angle brackets.

about 4 years ago · Juan Pablo Isaza Relatório

0

it is call "Destructuring_assignment" you can read more on that here

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment

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