0

I am facing an issue by trying to loop through arrays/objects. When I loop through the set of arrays, showed by the screendump, it just output blank results. But when I console.log the data I am trying to loop through, it shows up like the screendump below. The main problem is that I can't loop through the data for some reason.

Edit: systems variable, is containing the output of the objects/array

I have tried this, but that output blank:

$.each(systems, function(index, value){
    console.log(value);
})

enter image description here

simon
  • 2,235
  • 6
  • 33
  • 53

2 Answers2

0

console.log is usually used to print simple strings.

When you want to examine more complex objects, such as arrays, HTML elements, objects etc, you should use console.info:

console.info(systems);

This will allow you to browse through the array, expand its sub-elements and examine it in a clearer way.

See this snippet for an example, and consider your browser's dev console will probably show it much better:

var systems = ['mac', 'windows', 'linux', 'ios'];
console.info(systems);

Here's how it looks in Google Chrome's dev console:

enter image description here

Koby Douek
  • 16,156
  • 19
  • 74
  • 103
0

First make sure that your systems variable is not empty. You can iterate data with for loop:

for (let k in systems) {
    console.log("k = ");
    console.log(systems[k]);
}
mitch
  • 2,235
  • 3
  • 27
  • 46
  • It's very weird. The system variable aint empty, it contains the output in the screendump, but when I loop with your code, It outputs blank. – simon Aug 18 '17 at 07:53