Ankit Kumar
Ankit Kumar

Reputation: 193

getting keys form the json file using node.js

I'm trying to get the keys from this json file but dont know how to get it

var request = require('request');
request('http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452', function(error, response, data) {
    if (!error && response.statusCode == 200) {

        //console.log(data) 
    }
})

Upvotes: 1

Views: 76

Answers (1)

Nick D
Nick D

Reputation: 1493

Check out the Object.keys() Method:

var arr = ['a', 'b', 'c'];
console.log(Object.keys(arr)); // console: ['0', '1', '2']

// array like object
var obj = { 0: 'a', 1: 'b', 2: 'c' };
console.log(Object.keys(obj)); // console: ['0', '1', '2']

// array like object with random key ordering
var an_obj = { 100: 'a', 2: 'b', 7: 'c' };
console.log(Object.keys(an_obj)); // console: ['2', '7', '100']

Source

Upvotes: 2

Related Questions