Does anyone know how to group nested arrays in Javascript like this? (can be vanilla or lodash method) (I work on Reactjs)
from
[[ 5, '103' ], [ 3, '104' ], [ 1, '105' ], [ 1, '106' ], [ 2, '107' ], [ 1, '108' ], [ 5, '109' ], [ 3, '110' ]]
to
{5: ['103','109'], 3: ['104','110'], 2: ['107'], 1: ['105','106','108']}
or
[[5, ['103','109']], [3, ['104','110']], [2, ['107']], [1, ['105','106','108']]]
Thank you
forEach. 3. In theforEachfunction body, get the current subarray, and the first and second element of it and assign them to variables. 4. Assign the first element to a key in the output object, and 5. append the second element to an array that is the value of the key.