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

124
Visualizações
i have data in the form of object of object in javascript

Hi everyone I have object of object and I just want to combine data inside inner object in the form of array is there any way to that

input data

  let data = {
      
      ok123b:{
        name:'shanu'
    },
       of123b:{
        name:'rahul'
    },
       og1453jdfk:{
        name:'ak'
    },
       ok1kjjdde23b:{
        name:'man'
    }
      
      
    }
    
    let arrayOfData  =[data.ok123b.name,data.of123b.name,data.og1453jdfk.name,data.ok1kjjdde23b.name]
    console.log(arrayOfData);
    
    //this is hard coded i want dynamic code to convert data in the form of array

expected output

output  = ['shanu','rahul','ak','man'];
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

There are several ways you can achieve this. I have updated my answer to include these.

Solution 1 (For loop and push() method)

You can use a simple for loop and push (add) each object's name to the array.

let data = {
  ok123b:{name: 'shanu'}, 
  of123b:{name: 'rahul'}, 
  og1453jdfk:{name:'ak'}, 
  ok1kjjdde23b:{name: 'man'}
}
let arrayOfData = [];
for(item in data) {
  arrayOfData.push(data[item]['name'])
}
console.log(arrayOfData);

Solution 2 (Using Object.values() and map() method)

let data = {
  ok123b:{name: 'shanu'}, 
  of123b:{name: 'rahul'}, 
  og1453jdfk:{name:'ak'}, 
  ok1kjjdde23b:{name: 'man'}
}
let r = Object.values(data);
let result = r.map((element) => element.name)
console.log(result);

Solution 3 (One liner using Object.entries() and map() method)

let data = {
  ok123b:{name: 'shanu'}, 
  of123b:{name: 'rahul'}, 
  og1453jdfk:{name:'ak'}, 
  ok1kjjdde23b:{name: 'man'}
}
let result = Object.entries(data).map(a=>a[1].name)
console.log(result);

However as @Chris G mentioned, this is a very common question so you should probably browse similar questions such as:

  • Merge Objects
  • How can I merge properties of two JavaScript objects dynamically?
about 4 years ago · Juan Pablo Isaza Relatório

0

hi everyone if any one have same problem here is the solution

let data = {
  
  ok123b:{
    name:'shanu'
},
   of123b:{
    name:'rahul'
},
   og1453jdfk:{
    name:'ak'
},
   ok1kjjdde23b:{
    name:'man'
}
  
  
}
let r=Object.values(data);


let result =r.map((el) =>el.name)
console.log(result);

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