In the following code snippet, I am gathering variables from an array of objects and then combining them into a single new object with other variables. Here is a simplified example:
var y = 10;
var x = [
{name: "name1", values:[1,2,3]},
{name: "name2", values:[3,4,5]}
];
var newObj = {y:[],x:[]}
for (var j=0;j<x.length;j++){
newObj.x.push([])
for (var i=0;i<x[j].values.length;i++){
newObj.x[j].push(x[j].values[i]);
}
}
newObj.y=y
console.log(newObj)
This works for what I am doing, but I am sure it is not even remotely best practices. What would be a more elegant way of organizing the values array from x into the new object with the single value for y?