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

99
Visualizações
JavaScript Object.values from an array of object

Here is my object:

const arr = [
  { name: 'Breaking Bad S01E07' },
  { name: 'Breaking Bad S01E06' },
  { name: 'Dexter S01E05' },
  { name: 'Dexter S01E02' },
  { name: 'Dexter S01E07' },
];

I want to extract just values and I used Object.values but it don't change.

Here is my code:

val = Object.values(arr);
console.log(val);

But what I get is exactly the same without Object.values. It doesn't return values. I returns keys + values.

I used map on it cuz it is an array of objects but it returns undefined!

const map = arr.map((x) => {
  Object.values(x);
});
console.log(map);

here is what I get:

[ undefined, undefined, undefined, undefined, undefined ]
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You will need to map and then destructure the name from each object.

const arr = [
  { name: 'Breaking Bad S01E07' },
  { name: 'Breaking Bad S01E06' },
  { name: 'Dexter S01E05' },
  { name: 'Dexter S01E02' },
  { name: 'Dexter S01E07' },
];

const values = arr.map(({ name }) => name);

console.log(values);

If you want all the values without their keys, you could try reducing the values.

const arr = [
  { name: 'Breaking Bad S01E07' },
  { name: 'Breaking Bad S01E06' },
  { name: 'Dexter S01E05' },
  { name: 'Dexter S01E02' },
  { name: 'Dexter S01E07' },
];

const values = arr.reduce((acc, obj) => [...acc, ...Object.values(obj)], []);

console.log(values);

about 4 years ago · Juan Pablo Isaza Relatório

0

The map function should always return a value.
You can change your map function in this way.

const map = arr.map((x) => Object.values(x));
console.log(map);
about 4 years ago · Juan Pablo Isaza Relatório

0

You are not returning anything from map callback function, hence, it populates the resultant array with undefined

const arr = [
  { name: 'Breaking Bad S01E07' },
  { name: 'Breaking Bad S01E06' },
  { name: 'Dexter S01E05' },
  { name: 'Dexter S01E02' },
  { name: 'Dexter S01E07' },
];

// Using object.values

const val = arr.map(item => Object.values(item)[0]);

// OR Accessing value directly
const values = arr.map(item => item.name)


console.log(values, val);

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