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

171
Vistas
The Object.fromEntires() change the sequence of the values in an array when key is numerical-- Javascript

I have a array:

arr = [ ['1', 'a'], ['12', 'b'], ['2', 'c'] ];

I'm using Object.fromEntries() to convert the array into objects with key/value pair. But the problem is Object.fromEntries() seems to changing the sequence of my array based on the key, eg: I want my above array to be converted into object with the same sequnce as shown in the code:

expected o/p:

{1: 'a', 12: 'b', 2: 'c'}

Actual o/p from the fromEntires()

{1: 'a', 2: 'c', 12: 'b'}

any idea why does the function do that and if there is a way to avoid this and render the same sequcne as provided in the array?

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

The order of properties in JavaScript objects is not guaranteed to be the insertion order. In particular, keys that parse as integers (such as in your case) will not respect insertion order.

If you need to guarantee order, try using a Map instead:

let arr = [ ['1', 'a'], ['12', 'b'], ['2', 'c'] ];
const map = new Map();
for(let value of arr){
 map.set(value[0], value[1])
}
about 4 years ago · Santiago Gelvez 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