I want transform my array to array of arrays by attribute "icon".
const array = [
{ icon: true },
{ icon: false },
{ icon: false },
{ icon: true },
{ icon: false }
]
I need:
[[{icon: true}, {icon: false}, {icon: false}], [{{icon: true}, {icon: false}}]]
Attribute icon === true
is a sign of the beginning of the formation of a new array.
I think you should use the function reduce.
array.reduce((result, item, index) => { ... }, [])
How best to write a transformation? Thanks!