How to parse an array of JSON data

Published on: April 16, 2017

Welcome to the 42nd Easy JavaScript tutorial, part of EasyProgramming.net. In this tutorial learn how to parse an array of JSON data with what we have learned so far.

We looked at the for...in loop last time, and I mentioned that you can take it one step further by dynamically creating javaScript Objects inside of an array, and iterate through the array and parse your JSON.  Be sure to check out the array.forEach() tutorial where I cover the forEach loop in much more detail!

This is extremely useful when you're trying to parse large sets of JSON data returned to you either through an API call or something that you generated. You can even use this to create a script like my JSON to Table which allows you to convert ANY JSON input into a neat HTML table.

Syntax of a for...in loop:

    for(property in object){
        //E.g. object - person = {name:"Nazmus"};
        var x = property; //name of the property itself - name
        var y = object[property]; //value of the property - Nazmus
    }
  

To fork the fiddle and follow along: https://jsfiddle.net/easyjs/kwhhLcv9/

Remember to checkout the Resources section below for associated downloadable content, JSFiddle links, and other resources. Watch the video and follow along!

Resources:



Comments: