For example: I have array that looks like this:
let arr = [{ name: "Peter" }, { name: "Peter" }, { name: "John" }, { name: "Peter" }, { name: "Sarah" }, { name: "John" }] I need to create array, that will be look like this:
let dupArray = [ [{ name: "Peter" }, { name: "Peter" }, { name: "Peter" }], [{ name: "John" }, { name: "John" }], [{ name: "Sarah" }] ] Again, it's not about duplicating, it's about creating new array with duplicates grouped.
dupArray = arr.sort();it sorts it alphabetically which in turn will group the duplicates together.