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

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

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 Report

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 Report

0

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

This will return an array with names.

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!