function foo(arr) { let newArr = arr.toString().split(","); let set = new Set(newArr); let a = Array.from(set); return a; } let x = foo([[1, 3, 2, 1], [5, 3, 4], [6, 2, 8, 9], 1, 4, 7]); console.log(x);