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

174
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 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