How to convert an object from API to JSON array in Angular 9?
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.


Leave a Reply

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to set opacity or transparency using CSS? #3 Pagination in CSS with multiple examples #4 How to make HTML form interactive and using CSS? #5 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

Mar 5 How to create flickering text using CSS? Mar 4 How to use data-* Attributes in HTML? Mar 4 The substr() method in JavaScript and how it’s different from substring() Mar 4 A complete guide to add responsive YouTube videos using HTML and CSS Mar 3 How to embed YouTube or other video links in WordPress? Mar 3 How to change the Login Logo in WordPress?

You might also like these

How to vertically align a html radio button to it’s label?CSSHow to Draw a Circle in HTML5 Using Canvas Tag?HTMLList of all Pseudo Elements in CSSCSSThe Differences Between HAVING Clause and WHERE Clause in SQLSQL/MySQLCONCAT and CONCAT_WS Functions in PostgresPostgresOOP, Class and Objects Strategies For Beginners (PHP)PHPDebugging in WordPress Part 3: SCRIPT_DEBUG and SAVEQUERIESWordPressCSS align-items property examplesCSSCan We Use For Loop to Loop Through Associative Arrays in PHP?PHPHow to Use SQL MAX() Function with Dates?SQL/MySQLsubstring() Method in JavaScriptJavaScriptHow to make HTML form interactive and using CSS?CSS