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

214
Views
Convert an object into array javascript

I have an object with these key-value pairs. This object comes from an API which I am calling :

APIName(obj).subscribe((res:any) => {
   console.log(Object.values(res.data));
})  



data = {
   0 : 1,
   1: 3,
   2: 7,
   3: 10
....so on
}

enter image description here

simply put it is an object of numbers and my desired output is (a simple array) :

data = [1,3,7,10]

I've tried Object.value and Object.key it still converts it into an object. Any help?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

First of all if your data is not sorted by key. Then sort it. and iterate through object and push to array.

var data = {
   1: 1,
   0: 3,
   2: 7,
   3: 10
};
let sortedKeys = Object.keys(data).sort();
let arrayOfData = [];
// iterate method
sortedKeys.forEach((key) => {
  arrayOfData.push(data[key]);
});
console.log(arrayOfData);

about 4 years ago · Santiago Trujillo 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!