Reputation: 501
I have a JSON object like
{
"key1" : "value1",
"key2" : "value2",
}
i need to convert this value as Javascript array by combining both the values like
var my_array = ["value1 value2"]; //value 1 and value 2 of JSON
I tried:
var obj = JSON.parse(countrylist);
var countries = [obj.value1+ " " + obj.value2];
Upvotes: 0
Views: 46
Reputation: 504
You can try this,
var obj = JSON.parse(countrylist);
var countries=Object.values(countrylist);
Here Object
is a builtin javascript object.
To get the keys you can use Object.keys(your_object)
Upvotes: 2