I am trying to play with an array. I created two buttons PushUP and PushDown. PushUp button will sort the array in forward manner and PushDown in reverse manner. I am trying so hard but failed to figure out but failed to do so. What should I write in order to get the following output. Also, how would I show this data before clicking any Push button and then change the order by button accordingly. For example, initially I want to show 2 buttons with the data.
For example, output should be something like that on clicking the following buttons.
Original array:
1 xyz
2 abc, 123
3 asd
On clicking PushUp:
3 asd
1 xyz
2 abc, 123
On clicking PushDown:
1 xyz
2 abc, 123
3 asd
My code:
var details = [
{intro: "ABC"},
{due: " MON"},
{name: "XYZ", sn: "SN xxxxx"},
{lab: "Tuesday 4:30-6:30"}
];
function Push_Up(){
details.sort();
displayPUSH();
}
function displayPUSH() {
document.getElementById("up").innerHTML =
"<br>" +
"CSIT128" + " :" + details[0].intro + "<br><br>" +
"Assignment 5"+ ", " + details[1].due + "<br><br>" +
details[2].name + ", " + details[2].sn + "<br><br>" +
"Computer LAB" + " :" + details[3].lab + "<br><br>";
}
function Push_Down(){
var details_after ="";
for ( var i=0; i<details.length; i++ )
{
displayPUSH();
}
document.getElementById("down").innerHTML = details_after;
}
<button onClick="Push_Up()"> Push Up </button>
<br>
<div id="up">
</div>
<button onClick="Push_Down()"> Push Down </button>
<br>
<div id="down">
</div>
<br>