score:0

just make sure that arrayx and arrayy have the same lengths.

let arrayx = ["02/01/2014", "14/10/2014", "03/05/2014"];
let arrayy = [2, 10, 8];

let data = [];

for (let i in arrayx) {
    data.push({
        x: arrayx[i],
        y: arrayy[i]
    });
}

console.log('data: ' + json.stringify(data));

score:0

one way of merging it would by map over one of the arrays with referring to index in second:

const arrayx = ["02/01/2014", "14/10/2014", "03/05/2014"];
const arrayy = [2, 10, 8];

const data = arrayx.map((item, index) => ({
  y: arrayy[index],
  x: item,
}));

console.log(data);

it results:

[
  { y: 2, x: '02/01/2014' },
  { y: 10, x: '14/10/2014' },
  { y: 8, x: '03/05/2014' }
]

in the case of deeper nested structures, small modifications need to be applied to accommodate them. eg.

const arrayx = [ ["02/01/2014", "14/10/2014", "03/05/2014"] ];
const arrayy = [2, 10, 8];

const data = arrayx[0].map((item, index) => ({ 
.....

Related Query

More Query from same tag