How to join the values of an object of a json to an array

11

I have this JSON.

[{
    GRUPO1: '3096',
    PER1: '0',
    PER2: '0',
    PER3: '0',
    PER4: '0',
    PER5: '0',
    PER6: '0',
    PER7: '3096',
    PER8: '0',
    PER9: '0',
    PER10: '0',
    PER11: '0',
    PER12: '0',
    TOTAL: '3096'
}]

What I need is to join all the values of the JSON objects in an array, so that it looks like this:

var json_devuelto = [];
json_devuelto = ['3096''0','0','0','0','0','0','3096','0','0','0','0','0','3096'];
    
asked by Jean Paul 29.08.2016 в 19:50
source

2 answers

11

You can do it directly with javascript, using the methods keys () and map () :

// en tu caso entrada sería tbla_altas[0]
var entrada = {"a":"10","b":"11","c":"12"};

var resultado = Object.keys(entrada).map(function(k) { return entrada[k] });

console.log(resultado);
    
answered by 29.08.2016 / 20:02
source
3

There is also the property Object#values that directly returns the values of the "keys":

var entrada = {"a":"10","b":"11","c":"12"};

var resultado = Object.values(entrada);

console.log(resultado);

Certainly what Mariano says in the comments, in fact, the documentation provided suggests several Polyfills:

Object # values and Object # entries of the spec

Object # values and Object # entries previously proposed

    
answered by 30.08.2016 в 16:06