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

102
Vistas
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 Respuestas
Responde la pregunta

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 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