Yogesh Chauhan's Blog

How to convert an object from API to JSON array in Angular 9?

in Angular on May 16, 2020

If you're getting the data using API, it will be easier to use an array to display data rather than an object.

Declare your array first in your component class:

array: [];

Then use JSON.stringify and JSON.parse to convert the object into an array.

ngOnInit()    {
        this.array = JSON.parse(JSON.stringify(data.object));

You can use that array to print your results from API data in html template.

For e.g.


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
How to make WordPress main stylesheet (style.css)?WordPressCSS align-items property examplesCSSWhat happens when we add Numbers and Strings in JavaScript?JavaScriptRIGHT JOIN in PostgresPostgresCanvas Drawing in HTML5HTMLWordPress: How to setup and get values from an ACF options page?WordPressIN and BETWEEN Operators in SQLSQL/MySQLHow to use PHPMailer to send an Email via Gmail SMTP Server?PHPWhat is a Strict Requirement in PHP 7 Function Declarations?PHPThe Lending Club Analysis using Logistic Regression and Random Forest in RStudioMiscellaneousDynamically generate names in SCSS (animation example)SCSSAll different methods for accessing elements in the DOM using JavaScriptJavaScript