0

I am using cryptocomare API to get crypto coins data within a Nextjs App. What i doing is that when a user clicks on a perticular symbol, i redirect it to the coin details page where i try to extract the clicked symbol with getServerSideProps as follows and then dynamically put in the API call and send it to the API server.

`

export const getServerSideProps = async (context) => {
  const res = await fetch(
    `https://min-api.cryptocompare.com/data/pricemultifull?tsyms=USD&fsyms=${context.params.symbol}`
  );  
  const icon = await res.json();
  return {
    props: {
      icon,
    },
  };
};

` This call returns a json object of nested objects and it goes to 2-3 levels deep. On Top it looks like following: API call response

Inside my code, I want to access the data Object -> RAW -> (whatever the user clicked on). But, Since the Symbol or coin queried by the user is dynamic (means i can't predict what is clicked) I never know what to query. SO i tried this to access the data object.RAW[0]

In principal it should give me the whatever object is inside the object.RAW But it returns undefined

Can please someone guide me , how can i get the data inside object.RAW without knowing what is inside? Thanks!

I have tried object.RAW[0] to access the data...,....

1 Answers1

0

You can use Object.values(object.RAW) to get an array of the values inside RAW (assuming RAW is not undefined)

Doc: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Object/values

Simon
  • 6,025
  • 7
  • 46
  • 98
  • Thanks, it solved the problem partially. However i also want to access the values inside object.RAW.USD . How would I do that? – Sverely Simple Nov 29 '22 at 14:57
  • Then you probably would have to do the sameon object.RAW.USD i.e. Object.values(object.RAW.USD). If it does not work please open a new question detailing what's needed and if my answer fixed your first pb, please accept it ;) – Simon Nov 29 '22 at 15:05