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

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

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 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!