q1) I have sorted the "var dd" first then I have iterated using "each", does the order in dd is followed by "each" or it can change the order in any case?
q2) do all the loops honour the sort order?
q3) if I declare the "var dd" as global var and sort it, then will it preserver the order inside the "var dd" all the time or is there any case where it can change?
q4) when we get data ordered from database using ajax function of jquery, is the data remains ordered or it can change in any case?
<script>
var dd = [
{ id: 2, dd: "t",type:"kk" },
{ id: 3, dd: "h",type:"kk" },
{ id: 1, dd: "k",type:"kk" },
]
dd.sort(function (a, b) {
return a.id - b.id;
});
$.each(dd, function (key, item) {
if (this.type == "kk") {
$('#div1').append($('<h2 id="h22">' + item.dd + '</h2>'));
}
});
</script>