Fathah Cr
Fathah Cr

Reputation: 501

Merging two JSON values as one to array

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

Answers (1)

Madhusudhan Aradya
Madhusudhan Aradya

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

Related Questions