jquery - Object Equality in jQuery3+ -


sample using jquery3.1: https://jsfiddle.net/pyb10ey9/

comparing same objects 2 different array in jquery3+ version , return false. can't able find differ.

the right way of comparing 2 objects using vanilla javascript, , possibly 1 of fastest, json.stringify(). bear in mind, introduced javascript 1.7 in 2006 , may not work on older browsers, can see here. still, on 97% global coverage pretty safe standards.

as can see in example, have rely on ordering of properties.

var data = { colors: [{     id: 1,     color: "red"   }, {     color: "green",     id: 2   }] }; var data1 = {   colors: [{     id: 1,     color: "red"   }, {     id: 2,     color: "green"   }] };  var isdataequal = json.stringify(data1.colors[1]) == json.stringify(data.colors[1]);       alert("jquery version : " + jquery.fn.jquery + "\n" + "isdataequal : " + isdataequal); 

working jsfiddle

very informative research


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -