I have an array as posted below in code section. What I am trying to achieve is, to process that array in such way that, it should be split into four different arrays based on the value of the property 'value'. So, for all entries in that mainArray with the same value of the property 'value', they should be pushed in a new array.
Is there any method or way in JavaScript that can achieve that task efficiently?
Code:
mainArray =
[ { key: '2', value: -20 },
{ key: '3', value: 0 },
{ key: '1', value: 10 },
{ key: '5', value: 10 },
{ key: '7', value: 10 },
{ key: '4', value: 40 },
{ key: '6', value: 40 },
{ key: '8', value: 40 } ]
Code 2:
[ { key: '2', value: -20 }] //array1
[{ key: '3', value: 0 }] //array2
[{ key: '1', value: 10 }, //array3
{ key: '5', value: 10 },
{ key: '7', value: 10 }]
[{ key: '4', value: 40 }, //array4
{ key: '6', value: 40 },
{ key: '8', value: 40 }]