I have an array of objects and I want to sort it by a property, but I want the sort function to ignore some rows.
Suppose I have the following array and would like to ignore index 1:
var datos = [
{"asd1":"prueba11", "asd2":"prueba12", "asd3":"prueba13", "asd4":"prueba14", "asd5":"prueba15"},
{"asd1":"prueba21", "asd2":"prueba22", "asd3":"prueba23", "asd4":"prueba24", "asd5":"prueba25"},
{"asd1":"prueba11", "asd2":"prueba42", "asd3":"prueba43", "asd4":"prueba44", "asd5":"prueba45"},
{"asd1":"prueba31", "asd2":"prueba32", "asd3":"prueba33", "asd4":"prueba34", "asd5":"prueba35"},
{"asd1":"prueba41", "asd2":"prueba42", "asd3":"prueba43", "asd4":"prueba44", "asd5":"prueba45"},
{"asd1":"prueba51", "asd2":"prueba52", "asd3":"prueba53", "asd4":"prueba54", "asd5":"prueba55"}
];
And I have the following function to order:
var x = "asd2";
datos.sort(function(a,b) {return (isNaN(a) && isNaN(b))?((a[x] > b[x]) ? 1 : ((b[x] > a[x]) ? -1 : 0)):(a - b);} );
How can I make it ignore (and keep in the same place) index 1?
I leave you an example I do not know if it is the functionality you are looking for, what I did was pass the Data array to a new array and you perform the sort on it, I investigated and I did not find how to directly ignore with any property or function for the Sort, apart from changing your function sort , the comparison in the IF you can change 1 to a variable or whatever you want