1

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) 
    }
})
3
  • You can get the keys by using Object.keys(data); Would be better if you can post the response json to get correct answers. :) Commented Apr 21, 2016 at 8:34
  • but that is just giving me numbers Commented Apr 21, 2016 at 9:03
  • that is why I asked your to post your received response :) Commented Apr 21, 2016 at 10:00

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.