How to convert JSON object to an Typescript array? How to convert JSON object to an Typescript array? arrays arrays

How to convert JSON object to an Typescript array?


To convert any JSON to array, use the below code:

const usersJson: any[] = Array.of(res.json());


That's correct, your response is an object with fields:

{    "page": 1,    "results": [ ... ]}

So you in fact want to iterate the results field only:

this.data = res.json()['results'];

... or even easier:

this.data = res.json().results;


You have a JSON object that contains an Array. You need to access the array results. Change your code to:

this.data = res.json().results