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 How to add Read More Read Less Button using JavaScript? #3 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #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

#Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface #Jan 14 How to display a student’s individual transcript in Colleague? #Jan 11 How to install PuTTY on a MacOS? #Jan 8 How to Install Xcode Command Line Tools on MacOS?
You might also like these
How to use PHPMailer to send an Email via Gmail SMTP Server?PHPHow to solve “framework not found” error in Swift?SwiftThe simple difference between var, let and const in JavascriptJavaScriptSafe Practice to add Links to cross-origin destinationUI/UXPostgreSQL transactions using the BEGIN, COMMIT, and ROLLBACK statements.PostgresIs there a difference between SCSS and Sass?SCSSHow to avoid element shift on border change while hovering in CSS?CSSOrder By and Group By in PostgresPostgresHow to Block IPs and User Agents using code in Drupal or WordPress?DrupalSolution to “Call to undefined function mysql_error()” in RevSlider WordPress PluginWordPress2 Ways we can create an Array in JavaScriptJavaScriptJavaScript: how to detect a browser using the user agent?JavaScript