I have list of arrays with different length. I want to find the highest length of the array in the list and make all remaining arrays of same length by filling null/empty value.
e.g: I have a list of array
[ [1,2,2,4,4], [2,3,2,4], [2,4,21,4], [1,2]];
I want to find the highest length of array in the list i.e 5 in above case ( length of [1,2,2,4,4])
I want to make all remaining arrays also of same length like below
[ [1,2,2,4,4], [2,3,2,4,''], [2,4,21,4,''], [1,2,'','','']];
How can I achieve that?
Sample code of list of array and finding max length
let data = [ [1,2,2,4,4],
[2,3,2,4], [2,4,21,4], [1,2]
];
const length = Math.max(...(data.map(el => el.length)));
console.log('array list', data);
console.log('max length', length);