1

I can't access to JSON object that exist inside another object , my code is like this:

var di = [ 
        { score: 0.75,
          obj:
           { _id: '8888888',
             title: 'diiiiiii',
             description: 'fdsf dfd sfjos sofjsof' } 
         },
        { score: 0.75,
          obj:
           { _id: '444444',
             title: 'dfssd ddd   ',
             description: 'sdfsfs', } 
         },
        { score: 0.75,
          obj:
           { _id: '55555',
             title: 'ffffood   ',
             description: 'iiiiiiiiii' } 
         } 
      ]; console.log(di.obj);

I get undifined

er_web-pr
  • 55
  • 1
  • 5

2 Answers2

2

di is an array, not an object. You must use di[0].obj to get the first object, di[1].obj to get the second, and so on.

MultiplyByZer0
  • 6,302
  • 3
  • 32
  • 48
0

of course not, its sitting inside an array. you gotta loop through it like this,

di.forEach(function(item)
{
    console.log(item.obj);
});
Irshu
  • 8,248
  • 8
  • 53
  • 65