I am trying to convert a json string to an array but i still get json code in return when i parse it.
var slag = [];
for(var i=0; i < data.length; i++)
{
var string = JSON.stringify(data[i]);
var parse = JSON.parse(string)
slag.push(parse);
}
console.log(slag);
now i still get this output
0: {id: "4", club: "driver", afstand: "230", shot: "straight", uitvoering: "perfect"}
1: {id: "9", club: "ijzer7", afstand: "140", shot: "straight", uitvoering: "perfect"}
but i want something like this in an array
[4, "driver", 240, "straight", "perfect"]
You need to extract values from the object, use Object.values
method after parsing the JSON string.
var parse = Object.values(JSON.parse(string))
FYI : You can do it directly to the object instead of stringifying and parsing(which doesn't makes any sense). So simply iterate and extract values from object using Object.values
method.
for(var i=0; i < data.length; i++){
slag.push(Object.values(data[i]));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With