Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!