Note that there are some explanatory texts on larger screens.

plurals
  1. POArray.sort working differently in chrome and firefox and IE
    primarykey
    data
    text
    <p>I'm trying to sort an array that contains objects, based on the field[marks] in the object. The array is getting sorted differently in Firefox and chrome. In Chrome and IE9 the sixteenth item gets shifted to the top of the array for no reason. Since all the marks are 0 I assumed no sorting will take place. No sorting happens in Firefox but that's not the case with chrome and IE. Please find the code below I have used. Any advice to why this happens would be much appreciated</p> <pre><code>var arr = [ {"userid":"1","name":"USER_1","subjectid":"123","marks":"0"}, {"userid":"2","name":"USER_2","subjectid":"123","marks":"0"}, {"userid":"3","name":"USER_3","subjectid":"123","marks":"0"}, {"userid":"4","name":"USER_4","subjectid":"123","marks":"0"}, {"userid":"5","name":"USER_5","subjectid":"123","marks":"0"}, {"userid":"6","name":"USER_6 ","subjectid":"123","marks":"0"}, {"userid":"7","name":"USER_7","subjectid":"123","marks":"0"}, {"userid":"8","name":"USER_8","subjectid":"123","marks":"0"}, {"userid":"9","name":"USER_9","subjectid":"123","marks":"0"}, {"userid":"10","name":"USER_10","subjectid":"123","marks":"0"}, {"userid":"11","name":"USER_11","subjectid":"123","marks":"0"}, {"userid":"12","name":"USER_12","subjectid":"123","marks":"0"}, {"userid":"13","name":"USER_13","subjectid":"123","marks":"0"}, {"userid":"14","name":"USER_14","subjectid":"123","marks":"0"}, {"userid":"15","name":"USER_15","subjectid":"123","marks":"0"}, {"userid":"16","name":"USER_6","subjectid":"123","marks":"0"}, {"userid":"17","name":"USER_17","subjectid":"123","marks":"0"}, {"userid":"18","name":"USER_8","subjectid":"123","marks":"0"}, {"userid":"19","name":"USER_19","subjectid":"123","marks":"0"}, {"userid":"20","name":"USER_20","subjectid":"123","marks":"0"}, {"userid":"21","name":"USER_21","subjectid":"123","marks":"0"}, {"userid":"22","name":"USER_22","subjectid":"123","marks":"0"}, {"userid":"23","name":"USER_23","subjectid":"123","marks":"0"}, {"userid":"24","name":"USER_24","subjectid":"123","marks":"0"}, {"userid":"25","name":"USER_25","subjectid":"123","marks":"0"}, {"userid":"26","name":"USER_26","subjectid":"123","marks":"0"}, {"userid":"27","name":"USER_27","subjectid":"123","marks":"0"}, {"userid":"28","name":"USER_28","subjectid":"123","marks":"0"}, {"userid":"29","name":"USER_29","subjectid":"123","marks":"0"}, {"userid":"30","name":"USER_30","subjectid":"123","marks":"0"}, {"userid":"31","name":"USER_31","subjectid":"123","marks":"0"}, {"userid":"32","name":"USER_32","subjectid":"123","marks":"0"}, {"userid":"33","name":"USER_33","subjectid":"123","marks":"0"} ]; console.log(JSON.stringify(arr)); arr.sort(function(a,b){ return b['marks'] - a['marks']; }); for(var i = 0; i &lt; arr.length; i++){ arr[i].position = i + 1; } console.log(JSON.stringify(arr));​ </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload