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

170
Vistas
Returning only Specified attributes of JSON data using find Function NativeJS

So I'm new to react native and am trying to return a single attribute of JSON data. I'm calling the CoinMarketCap API into a list of coin names, and when you click on the name it'll send you to a different page with a list of various attributes of the coin you clicked on. For example if you clicked on Ethereum, it'll show you the current price ($1,754), the symbol (ETH), the change in the last hour (-6.4%), etc. I'm using the find function to find the passed variable id name of the clicked coin. However when I return the data it prints the entire JSON data for that coin but I only want it to return specified attributes.

return JSON.stringify(Variables.LIST2.find(id => id.id == authorID));

Here's an example of what I mean with fruits

const fruits = [

{name: 'bananas', quantity: 2, color: 'yellow'},
{name: 'apples', quantity: 3, color: 'red'},
{name: 'grapes', quantity: 5, color: 'purple'},
];

const result = fruits.find( ({ name }) => name === 'apples' );
console.log(result) // output: { name: 'apples', quantity: 3, color: 'red'}

What would I do if I only wanted to return the name and the color instead of name quantity and color?

I've tried using parse but I still need to use find to locate the id from the passed navigation variable. What should I do?

// output: { name: 'apples', color: 'red'}

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

0

const fruits = [
    {name: 'bananas', quantity: 2, color: 'yellow'},
    {name: 'apples', quantity: 3, color: 'red'},
    {name: 'grapes', quantity: 5, color: 'purple'},
];  
const result = fruits.find( ({ name }) => name === 'apples' );
//console.log(result)
var obj = {name: result.name, color: result.color}

console.log(obj);

Hey, As far I know, we can't return object with specified attributes, So we have to go in a hardcoding way like I did. I hope it will be helpful for you.

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