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

274
Views
¿Cómo obtener valores únicos de una lista de objetos?

Datos:

 [ { "name": "Ankh of Anubis", "rank": { "_type": "medal", "current": "ankh-of-anubis" } }, { "name": "Bonus Roulette", "rank": { "_type": "medal", "current": "bonus-roulette" } }, { "name": "jetx", "rank": { "_type": "medal", "current": "jetx" } }, { "name": "Gates of Olympus", "rank": { "_type": "trophy", "current": "gates-of-olympus" } }, ]

Cómo filtrar solo valores únicos,

 uniqueValues = ["medal","trophy"]

Lo intenté,

  1. const uniqueTitles = new Set(games.category.title);
  2. const uniqueTitles = [...new Set(games.category.title)] //error mecanografiado.
 useEffect(() => { const uniqueTitles = games.filter((game:any) => { return new Set(game.category.title); }) setTitles(uniqueTitles); },[])
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Está utilizando Set como valor de retorno para una función de filtro. ¿Está realmente pensado de esa manera? Dados los datos:

 const data = [ { "name": "Ankh of Anubis", "rank": { "_type": "medal", "current": "ankh-of-anubis" } }, { "name": "Bonus Roulette", "rank": { "_type": "medal", "current": "bonus-roulette" } }, { "name": "jetx", "rank": { "_type": "medal", "current": "jetx" } }, { "name": "Gates of Olympus", "rank": { "_type": "trophy", "current": "gates-of-olympus" } }, ]

Puedes hacerlo:

 const uniqueValues = new Set(); data.forEach(record => uniqueValues.add(record.rank._type)); console.log(uniqueValues);

Aquí está el enlace .

about 4 years ago · Juan Pablo Isaza Report

0

Suponiendo que su matriz se llama data :

 const unique = [...new Set(data.map(item => item.rank._type))];

Créditos: https://stackoverflow.com/a/58429784/6320971

about 4 years ago · Juan Pablo Isaza Report

0

Solución similar a su primer intento:

 const data = [{"name":"Ankh of Anubis","rank":{"_type":"medal","current":"ankh-of-anubis"}},{"name":"Bonus Roulette","rank":{"_type":"medal","current":"bonus-roulette"}},{"name":"jetx","rank":{"_type":"medal","current":"jetx"}},{"name":"Gates of Olympus","rank":{"_type":"trophy","current":"gates-of-olympus"}},]; const uniqueValues = new Set(data.map(elem => elem.rank._type)); uniqueValues.forEach(value => console.log(value));

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!