JSFiddle - React, Tailwind, and code Playground

by jessikwa

JavaScript

//creating an obj that looks like yours, but suppose you
//already parsed your json into an obj
var jsonObj = {
    'follows': [ ]
}

for (i = 0; i < 5; i++) {
    var followObj = {
        'user': {
            '_id': 'testId'+i,
            'name': 'testName'+i
        }
    }
    jsonObj.follows.push(followObj);
}

var output = new Array();

//now loop through to get the name property of each
//user object in the follow array
for (var j = 0; j < jsonObj.follows.length; j++) {
    var thisName = jsonObj.follows[j].user.name;
    output.push("\n")
    output.push(thisName);
    output.push("\n")
}

alert(output.join(""));