For numbers, Boolean types, etc., just add the judgment directly at the end, or add them together. You will understand more clearly when I write it this way.
var a = ['{"1":1,"2":2}', {1:1, 2:2}, 'hello',{hello: '323651',bye: '43434'},[1,2,34],true,10,9,8,10,'true','hello',true,false,9,'9',{hello: '312312',ok: 32323},[1,2,34]];
var json = {};
var arr = [];
for (let i = 0, len = a.length; i < len; i++) {
let str = JSON.stringify(a[i]) + typeof a[i];
if (!json[str]) {
arr.push(a[i]);
}
json[str] = 1;
}
console.log(arr);
It is best to use another character to separate the JSONs. If you can only keep it as it is now, use 'hello' to split the array, and then compare to remove duplicates.
For numbers, Boolean types, etc., just add the judgment directly at the end, or add them together. You will understand more clearly when I write it this way.
Object vs Object and Array vs Array are processed recursively, and other cases are compared directly.Direct
===
judgment, if equal, it’s done.In case of inequality, if it is object vs object or array vs array, compare it with JSON stringify, and everything else will be fine.
If the object is in sequential order or the internal array elements are ordered arrays, then the elements are converted to strings and compared.
It is best to use another character to separate the JSONs. If you can only keep it as it is now, use 'hello' to split the array, and then compare to remove duplicates.
new Set()