Difference in Arrays

    0

    0

    Mansimar Anand

    Find difference in array in JavaScript

    function ArrayDiff(a, b){
      const setX = new Set(a)
      const setY = new Set(b)
    	
      return [
        ...a.filter(x=>!setY.has(x)),
        ...b.filter(x=>!setX.has(x))
      ]
    }
    const Array1 = [1, 2, 3];
    const Array2 = [1, 2, 3, 4, 5];
    console.log(ArrayDiff(Array1, Array2))
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.