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

154
Visualizações
declare Object with the same key names

Is there a way to declare a Object with the same key names in js ?

let Obj = {
   '1' : '1',
   '1' : '1',
   '1' : '1',
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

No. The names of the properties in an object must be unique, not least so you can identify the property you want to get/set. Although the code you wrote will parse and run, the resulting object will have only one property (the last one using that name):

let obj = {
    1: "first",
    1: "second",
    1: "third",
};
console.log(obj[1]);; // "third"

You could use an array of objects if the key name must be the same:

let array = [
    {1: 1},
    {1: 1},
    {1: 1},
];

...or, really, just an array (let array = [1, 1, 1];) as the key name isn't doing anything useful if it's always the same.

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