This is one of many other solutions you can do
const a = [
[1,1,2,1,3],
[2,1,4,4,5],
[3,1,4,5,1]
];
// flat the two dimensions array to one dimension array
const transformedArray = a.flat();
const unifiedArray = [];
const countDuplicates = [];
// create a new array containing unique values
// you can use the Set(..) object for this too
transformedArray.forEach(elem => {
if(!unifiedArray.includes(elem)) {
unifiedArray.push(elem);
}
});
// start counting
unifiedArray.forEach(elem => {
const countElem = transformedArray.filter(el => el === elem).length;
countDuplicates.push({
element: elem,
count: countElem
});
});
// test values
console.log(transformedArray);
console.log(countDuplicates);