I have an array of data [{a:12,b:20},{a:20,b:123}]
How I can convert this to [[12,20],[20,123]]
I have an array of data [{a:12,b:20},{a:20,b:123}]
How I can convert this to [[12,20],[20,123]]
You can use Array.map() using Object.Values() as the mapping method:
let input = [{a:12,b:20}, {a:20,b:123}];
let res = input.map(Object.values);
console.log(JSON.stringify(res));
.as-console {background-color:black !important; color:lime;}
.as-console-wrapper {max-height:100% !important; top:0;}
If you need to rely on order of the keys, then refer to @MarkMeyer answer, it can be more appropriate for your purposes.
It's a pretty one-liner with some destructuring:
let l = [{a:12,b:20},{a:20,b:123}]
let arr = l.map(({a, b}) => ([a, b]))
console.log(arr)
const data = [{a:12,b:20},{a:20,b:123}]
let result = []
data.forEach(d => result.push([d.a,d.b]))
console.log(result)
Extract the keys and loop it with your input variable. i have used map function to loop and get data in array format.
var input = [{a:12,b:20},{a:20,b:123}];
var keys = Object.keys(input[0]);
var output = [];
keys.forEach(function(key){
output.push(input.map((item) => item[key]))
})
console.log(output)