Q:

JavaScript storing data and iterating

While trying to store data inside an object and later retrieve it, I do not know the ideal way to store information inside javascript objects so that I can loop through the information.
I set up an object of arrays:
var resultObject = {name: [], function: [], group: [], photo: [], linkedin: []};

Then I loop through it:
function constructResultPage(data) {
    var resultHTML = "";
    var teamContainer = document.getElementById('teamInput');
    data.forEach(function(key,index) {
        resultHTML = "<div> + data.linkedin + data.photo + data.name + data.function + "</div>"
    });

    teamContainer.innerHTML = resultHTML

}

But resultObject is an object itself. Would you recommend that I store every array inside a single array to loop over the items one at a time? or is there in your opinion a better way of achieving this?

A:

Try storing data in one array rather than four different. Consider running and experimenting with the snippet below.

var content = document.getElementById('content');

// single array containing objects of similar kind
var data = [
  {
    name: 'Suzanne',
    job: 'Developer',
    something: 'S1'
  },
  {
    name: 'John',
    job: 'Developer',
    something: 'S2'
  },
  {
    name: 'Alice',
    job: 'Manager',
    something: 'S3'
  },
  // etc.
];

data.forEach(function(person) {
    var personInfoDiv = document.createElement('div');
    personInfoDiv.innerHTML = 'Name: ' + person.name + '; Job: ' + person.job + '; Something: ' + person.something;
    content.appendChild(personInfoDiv);
});
<div id="content"></div>

