unique object in array

    0

    0

    [ { "name":"Thang" }, { "name":"Thien" }, { "name":"Ngu" }, { "name":"Thang" }, { "name":"Thang" }, { "name":"Thang" }, { "name":"Thang" }, { "name":"Thang" }, { "name":"An" }, { "name":"Den" }, { "name":"Den" }, { "name":"Sang" }, { "name":"Que" }, { "name":"Que" }, { "name":"Que" }, { "name":"Que" }, { "name":"Que" },]

    const array =[{ "name": "Thang" }, { "name": "Thien" }, { "name": "Ngu" }, { "name": "Thang" }, { "name": "Thang" }, { "name": "Thang" }, { "name": "Thang" }, { "name": "Thang" }, { "name": "An" }, { "name": "Den" }, { "name": "Den" }, { "name": "Sang" }, { "name": "Que" }, { "name": "Que" }, { "name": "Que" }, { "name": "Que" }, { "name": "Que" },]
    
    for (let i = 0; i < array.length - 1; i++) {
      const f = array[i]?.['name'] || null
      let flag = array[0]?.['name']
      let dub = null
      for (let j = i + 1; j < array.length; j++) {
        const s = array[j]?.['name'] || null
        if (f === s || flag === s) {
          array.splice(j, 1)
          if (dub === s) {
            array.splice(j, 1)
          }
          dub = s
        } else {
          flag = array[j].name
        }
    
      }
    }
    console.log(array);
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.