-1

I want to iterate through this array so I can print all the topic_name within the array.

a = [
 {
 "topic_name": "abc",
 "rdf_id": "pyt1.1",
 "ex_name": "hello_world",
 "line_number": "1",
 "code": "some code",
 "comment": "some comment"
 },
 {
  "topic_name": "abc",
  "rdf_id": "pyt1.2",
  "ex_name": "hello_world",
  "line_number": "2",
  "code": "some code",
  "comment": "some comment"
  },
]

i have tried the following...but no help

for(var i = 0; i < a.length; i++) {
  var item_name = a[i];
  var arr = item_name.topic_name;
  console.log(arr);
}

1 Answers1

1

You can try something like this:

arr.map(function(item) {
  return item.topic_name;
});
//=> ["abc", "abc"]
Hunan Rostomyan
  • 2,176
  • 2
  • 22
  • 31