I have this sample data and transformed it into an array of objects like the one below. This has two levels: Level1, and Level2.
var array = [{
"Level1": "Assigned to",
"Level2": "Assigned To 1"
}, {
"Level1": "Assigned to",
"Level2": "Assigned To 2"
}, {
"Level1": "Assigned to",
"Level2": "Assigned To 3"
}, {
"Level1": "Location1",
"Level2": "SubLocation 1"
}, {
"Level1": "Location1",
"Level2": "SubLocation 2"
}];
I want to group it by their Key, and below it will be the name/values of the key. (see sample below). How will I fix this so that in my HTML it will be.
<div id="accordion">
<h3>Assigned to</h3>
<div>
<p>Assigned To 1</p>
<p>Assigned To 2</p>
<p>Assigned To 3</p>
</div>
<h3>Location</h3>
<div>
<p>SubLocation 1</p>
<p>SubLocation 2</p>
</div>
</div>
var uniqueLevel1 = {}; $.each(json, function() { uniqueLevel1[this.Level1] = this.value; }); $.each(uniqueLevel1, function(l1) { $('#details').append('<h3>' + l1 + '</h3>'); });