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

173
Views
How to convert particular key value from object to array javascript

I would like to know how to get particular key from object and convert to array in javascript

var result = Object.entries(obj).includes(obj.name || obj.country || obj.account || obj.pincode).map(e=>e);

var obj = {
  "name" : "Sen",
  "country": "SG",
  "key" : "Finance",
  "city": "my",
  "account":"saving",
  "pincode":"1233"
}

Expected Output

["Sen", "SG", "saving", "1233"]

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Create an array of requested keys and then map it and take the values from the original object:

 const obj = {"name":"Sen","country":"SG","key":"Finance","city":"my","account":"saving","pincode":"1233"} const keys = ['name', 'country', 'account', 'pincode'] const result = keys.map(k => obj[k]) console.log(result) // ["Sen", "SG", "saving", "1233"]

about 4 years ago · Juan Pablo Isaza Report

0

I think you can try it like this.

There're other ways to get that result, too. Here's just a simple solution.

var obj = {
  "name" : "Sen",
  "country": "SG",
  "key" : "Finance",
  "city": "my",
  "account":"saving",
  "pincode":"1233"
}

let arrObj = []

let result = arrObj.push(obj.name, obj.country, obj.account, obj.pincode)

console.log(arrObj)
about 4 years ago · Juan Pablo Isaza Report

0

If you want an array based on a known, hardcoded list of properties, the easiest option is an array literal:

const result = [obj.name, obj.country, obj.account, obj.pincode];

A benefit of this approach is that it guarantees the order of values in the array. While the order is predictable in your example (one onject literal), f your objs are created in different places, the order of the values may not always be the same.

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!