-2

I have the following, simple JSON structure:

{
"a": {
    "value1": "w",
    "value2": "x"
},
"b": {
    "value1": "w",
    "value2": "x"
},
"c": {
    "value1": "w",
    "value2": "x"
}

}

...the desired output is as follows:

{
{
    "value1": "w",
    "value2": "x"
},
{
    "value1": "w",
    "value2": "x"
},
{
    "value1": "w",
    "value2": "x"
}

}

It would have to be plain Javascript (no jQuery). Thanks in advance.

tom33pr
  • 853
  • 2
  • 12
  • 30

1 Answers1

1

You could use the keys and map the values.

var object = { a: { value1: "w", value2: "x" }, b: { value1: "w", value2: "x" }, c: { value1: "w", value2: "x" } },
    array = Object.keys(object).map(function (key) { return object[key]; });

console.log(array);
.as-console-wrapper { max-height: 100% !important; top: 0; }

With upcoming ES7 Object.values, you could use just the result.

var object = { a: { value1: "w", value2: "x" }, b: { value1: "w", value2: "x" }, c: { value1: "w", value2: "x" } },
    array = Object.values(object);

console.log(array);
.as-console-wrapper { max-height: 100% !important; top: 0; }
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392