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

104
Visualizações
how to add property to object to desired position when i have data like this in js
z = {
    Asf:46,
    sage:46,
    fdfds:58,
  };
  z["619"] = 48;
  console.log(z);

// I try to add to the bottom of the object but it add to the top the object it just because of the string passing in terms of numbers but I tried other solution it won't work

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

0

I try to add to the bottom of the object but it add to the top the object

The order of properties in an "ordinary" JavaScript object such as yours is set out by the specification. For the properties in your example, the 619 property comes first in that order, because it's an "array index" property name, those come before non-array index property names.

You can't change that, but more importantly, relying on object property order is almost always a bad idea. If you want order, use an array or a Map. For instance, in your case, you might want a Map, which is ordered purely by the order in which you add entries to it:

const map = new Map([
    ["Asf", 46],
    ["sage", 46],
    ["fdfds", 58],
]);
map.set("619", 48);

Live Example:

const map = new Map([
    ["Asf", 46],
    ["sage", 46],
    ["fdfds", 58],
]);
map.set("619", 48);
console.log([...map]);
.as-console-wrapper {
    max-height: 100% !important;
}

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