1

I am looping an array in order to retrieve the objects inside it.

vm.dataFilesList = [{
    title: 'madrid',
    name: 'castles'
}, {
    title: 'spain',
    name: 'horses'
}, {
    title: 'story',
    name: 'oslo'
}, {
    title: 'beach',
    name: 'miami'
}];


for (var j = 0; j < vm.dataFilesList.length; j++) {
    console.log('file ' + vm.dataFilesList[j])
}

What I see in the console is: [object Object] four times; instead of:

file  Object {title: "madrid", name: "castles"}
file  Object {title: "spain", name: "horses"}
file  Object {title: "story", name: "oslo"} 
file  Object {title: "beach", name: "miami"}

Any suggestions?

Thanks!

  • See this answer: http://stackoverflow.com/questions/23310353/how-to-read-json-result-in-jquery/23310376#23310376 it's all about JSON to JavaScript objects – toesslab Sep 02 '15 at 06:43

2 Answers2

0

You should try with:

console.log('file ' + JSON.stringify(vm.dataFilesList[j]))
naoxink
  • 595
  • 1
  • 12
  • 19
0

try this

for (var j = 0; j < vm.dataFilesList.length; j++) {
    console.log('file ' + vm.dataFilesList[j].title + ' ' + vm.dataFilesList[j].name);
}
Shahid Ahmed
  • 494
  • 2
  • 4
  • 10