I recieved
li
tag from html
<li data-group="man">
<span>15</span>
<h5>alex</h5>
</li>
<li data-group="man">
<span>20</span>
<h5>jack</h5>
</li>
<li data-group="man">
<span>30</span>
<h5>john</h5>
</li>
<li data-group="woman">
<span>25</span>
<h5>Kianna</h5>
</li>
<li data-group="woman">
<span>17</span>
<h5>ela</h5>
</li>
<li data-group="woman">
<span>25</span>
<h5>Emery</h5>
</li>
I want to produce li using foreach
and than convert them into an object if they have the same data-group.
"man":{
"alex":15,
"jack":20,
"john":30
},
"woman":{
"Kianna":25,
"ela":17,
"Emery":25
}
Finally, they should be assigned
to an empty object
objects should not be as forms of 0,1,2...