How to filter duplicate sub-arrays of integers and strings from two dimensional array in Javascript -
i receiving 2-dimensional array of both integers , strings, , want remove duplicates them:
original array = [["admin", 2, "regular"], ["customer", "regular"], ["regular", "customer"], [1], ,["admin"], [1], ["admin"]
expected result = [["admin", 2, "regular"], ["customer", "regular"], [1], ["admin"]]
please how can in javascript?
does matter if array (and it's sub-arrays) gets reordered? if doesn't, then:
var array = [["admin", 2, "regular"], ["customer", "regular"], ["regular", "customer"], [1],["admin"], [1], ["admin"]]; array = array.map(x => x.sort()).sort(); var uniquearray = []; uniquearray.push(array[0]); (var = 1; < array.length; i++){ if (json.stringify(array[i]) != json.stringify(array[i-1])){ uniquearray.push(array[i]); } } console.log(uniquearray);
Comments
Post a Comment