I'm searching for a more elegant ES6 solution to transform this array:
var src = [{x:1,y:'a'},{x:2,y:'b'}];
Into this array:
var desc = [[1,2],["a","b"]];
This new array should contain one array for all properties and another array for all values.
Here is the code I currently have:
var src = [{x:1,y:'a'},{x:2,y:'b'}];
var prop1 = [];
var prop2 = [];
src.forEach(item => {
prop1.push(item.x)
prop2.push(item.y);
});
var desc = [prop1, prop2];
While it works well, it feels lengthy. So, any suggestions for improvement with shorter code would be appreciated.