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

148
Vistas
Get name from JSON JS

In JS I get a response in string ex.

[{"id":"1a869e62-8993-33d0-bd54-f33753044ced","name":"Cubsonx"},{"id":"c534bcba-0096-3668-a34e-a35435e6aafb","name":"Paulina453"}]

And from that I want to only have names, ex.

[{"name":"Cubsonx"},{"name":"Paulina453"}]

and then render every name that is on the list in an discord.js embed fields.

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

0

Parse the string to an object:

const jsonObj = '[{"id":"1a869e62-8993-33d0-bd54-f33753044ced","name":"Cubsonx"},{"id":"c534bcba-0096-3668-a34e-a35435e6aafb","name":"Paulina453"}]';

const obj = JSON.parse(jsonObj);

then map the array to the desired one:

const names = obj.map((item) => ({ name: item.name }));

and if you need a string again, then stringify the result:

const stringNames = JSON.stringify(names);
about 4 years ago · Juan Pablo Isaza Denunciar

0

Using _.map from lodash:

const getNames = function(obj) {
  return {
    name: obj.name
  }
}

const data = [{"id":"1a869e62-8993-33d0-bd54-f33753044ced","name":"Cubsonx"},{"id":"c534bcba-0096-3668-a34e-a35435e6aafb","name":"Paulina453"}]


const newArray = _.map(data, getNames)
console.log(newArray) //result: [{"name":"Cubsonx"},{"name":"Paulina453"}]

Using plain JS Array.map MDN: Array.prototype.map

const data = [{"id":"1a869e62-8993-33d0-bd54-f33753044ced","name":"Cubsonx"},{"id":"c534bcba-0096-3668-a34e-a35435e6aafb","name":"Paulina453"}]

const newArray = data.map((item) => ({ name: item.name }))
console.log(newArray) //result: [{"name":"Cubsonx"},{"name":"Paulina453"}]
about 4 years ago · Juan Pablo Isaza Denunciar

0

arr.map((el) => el.name);

This will return an array with names.

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