[advanced programming] js array deduplicates any type

write a function to remove duplicates of any type in the js array:
input: [a "," a ", 0,0, {}, {code 1}, {aV1}, [], [], [1], [1], null, null, undefined,undefined, /\ .js $/, /\ .js $/, /\ .js $/]
output: [" a ", 0, {}, {avell}, [], [1], null, undefined /\ .js $/]


const unique = (array) => {
    let obj = {}
    return array.filter((item, index) => {
      // key
      let newItem = item + JSON.stringify(item)
      return obj.hasOwnProperty(newItem) ? false : obj[newItem] = true
    })
}

clipboard.png


this is not deduplication of any type, this is array deduplication

Menu