Javascript json returning undefined -
so i'm trying grab data json object through in loop , keeps returning undefined. here code:
router.get('/', function(req, res, next) { request('https://api.instagram.com/v1/media/popular?client_id=############', function (error, response, body) { json = json.parse(body); var popular_tags = []; (var key in json['data']){ tag = json.stringify(key['tags']) popular_tags.push(tag) } console.log(popular_tags) res.render('index', {title: body }); }); });
this output recieve:
[ undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined ]
however, when try
var popular_tags = []; popular_tags.push(json['data'][0]['tags']) console.log(popular_tags)
it print out want. suggestions?
change line to
tag = json.stringify(json['data'][key]['tags'])
Comments
Post a Comment