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

171
Vistas
reduce() object by arraykey is not using the first key javascript
const cliente = {
    nome: "Andre",
    idade: 36,
    cpf: "123.456.789.10",
    email: "andre@gmail.com"
}

const chaves = ["nome", "idade", "cpf", "email"];

const clienteString = chaves.reduce((acum, curr) => acum += curr + ":" + cliente[curr] + ";")
 
console.log(clienteString);

the current output is: **nome**idade:36;cpf:123.456.789.10;email:andre@gmail.com;

the value of the key "nome:" is not being considered in the string

it should output this: nome:Andre;idade:36;cpf:123.456.789-10;email:andre@gmail.com;

what am i doing wrong?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This is a simpler version that does what you want:

const cliente = {
  nome: "Andre",
  idade: 36,
  cpf: "123.456.789.10",
  email: "andre@gmail.com",
};

console.log(
  Object.entries(cliente)
    .map(([key, value]) => `${key}:${value};`)
    .join("")
);

Object.entries returns an array of ["key", "value"]. Then we map over that and turn it into an array of "key:value;". Then we join the array of "key:value;" into a string.

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