Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

175
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda