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

138
Views
javascript convert object to array of objects with key value labels

Say i have an object like this..

const obj = {
  streaming_tile_x: 608,
  streaming_tile_z: 608,
  global_total_mesh_count: 9776,
  global_total_asset_count: 17831,
  global_total_texture_count: 64055,
  global_total_entity_count: 0,
  global_total_shader_count: 9776,
}

How can i convert it to an array of objects like this...

const results = [
    { 
        name: "streaming_tile_x", 
        value: 608 
    },
    { 
        name: "streaming_tile_z", 
        value: 608 
    },
    { 
        name: "global_total_mesh_count", 
        value: 9776 
    },
    { 
        name: "global_total_asset_count", 
        value: 17831 
    },
    { 
        name: "global_total_texture_count", 
        value: 64055 
    },
    { 
        name: "global_total_entity_count", 
        value: 0 
    },
    { 
        name: "global_total_shader_count", 
        value: 9776 
    },
]
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Use Object.entries() with map() and array destructuring:

const obj = {
  streaming_tile_x: 608,
  streaming_tile_z: 608,
  global_total_mesh_count: 9776,
  global_total_asset_count: 17831,
  global_total_texture_count: 64055,
  global_total_entity_count: 0,
  global_total_shader_count: 9776,
};

const result = Object.entries(obj).map(([name, value]) => ({name, value}));

console.log(result);

about 4 years ago · Juan Pablo Isaza Report

0

Object.keys(obj).map(key => ({name: key, value: obj[key]}))
about 4 years ago · Juan Pablo Isaza Report

0

You can use a simple for in loop to make this new array

const obj = {
  streaming_tile_x: 608,
  streaming_tile_z: 608,
  global_total_mesh_count: 9776,
  global_total_asset_count: 17831,
  global_total_texture_count: 64055,
  global_total_entity_count: 0,
  global_total_shader_count: 9776,
}

let array = []

for (let object in obj) {
  array.push({
    name: object,
    value: obj[object]
  })
}

console.log(array)

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!