Printing value out of object with always changin key

Hi,

I am trying to print a value out of an object that is not array, but have unique key into the object everytime an api throws result below is 2 example :

in json :
1st result search:

terms.357.price = 100 

2nd result search:

terms.123.price = 100

this always change per api request.

I cant specify in the html like :

{{ term.123.price }}

but it should be :

{{ term.[key].price }}

is there anyway we can do this?

as I tried using the ngFor it is not available to not an array???

I suggest thinking backwards. If your template wants to be displaying a repeated bunch of markup for each of several elements, then turn whatever you are getting from this API into an array.

its a 3rd api, so its not possible for me to change that part I am afraid

every search will popup json array nested with that particular data that I need to access, but its having a unique number each search, making it hard to retrieve

I mean transform the value in your service that interacts with the API. My primary point is that I would write the template the easiest way to write the template, and then backfill the data to match that, instead of doing the hard work in the template.

so meaning process it on the server end that pulls the api then serve it in the template end?

No, not necessarily. I never interact directly with HttpClient in pages. I always write injectable services that do that, and in that service is where I would do this data massaging. What comes out of the service should be an Observable<Foo[]> or Observable<Foo> or whatever makes the template easiest to write.

hmm not following I am afraid :frowning_face:

anyway some notes : I solved it using Object.keys to get the keys and then pull the variable with the keys I have retrieved :slight_smile:

this.keys = Object.keys(data.terms);

this will retrieve the key I need to get the value