Tengo:
['a', 'b', 'd', 'a', 'f', 'b', 'a', 'b']Me gustaría tener:
[['a', 'a', 'a'], ['b', 'b', 'b'], ['d'], ['f']]Puedes hacerlo así:
const test = ["a", "b", "d", "a", "f", "b", "a", "b"] function parseElements(elements) { const temp = {} for (const element of test) { if (!temp[element]) { temp[element] = [] } temp[element].push(element) } return [...Object.values(temp)] } const result = parseElements(test)