Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!