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

133
Views
Pregunta básica de Stringify con función de devolución de llamada

Entonces comencé a aprender json y tengo una pregunta.

 const rabbit = { name: 'BobJ', color: 'black', size: null, birthDate: new Date(), jump: () => { console.log(`${name} can jump!`); } } json = JSON.stringify(rabbit, (key, value) => { console.log(`key: ${key}, value: ${value}`); return key === 'name' ? 'Elsa' : value; }); console.log(json)

esta *return key === 'name' ? 'Ellie' : value;* parte significa que si hay una clave de 'nombre', establezca el valor en Ellie, de lo contrario, devuelva su valor original.

¿Qué sucede si quisiera tener más de 2 claves en ese código? como nombre y color ? como seria el codigo

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Podrías poner varias condiciones if else .

 if (key === 'name') { return 'Elsa' } else if (key === 'color') { return 'Green' } // if nothing else return value

También podría usar una declaración de cambio . O un ternario anidado .

Me gusta usar un hashmap/objeto para esto.

 const rabbit = { name: 'BobJ', color: 'black', size: null, birthDate: new Date(), jump: () => { console.log(`${name} can jump!`); } } const keyMap = { name: "Elsa", color: "Green", } json = JSON.stringify(rabbit, (key, value) => { console.log(`key: ${key}, value: ${value}`); return keyMap[key] || value }); console.log(json)

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!