How to get the difference between two arrays in JavaScript?

Is there a way to return the difference between two arrays in JavaScript?

For example:

var a1 = ['a', 'b']; var a2 = ['a', 'b', 'c', 'd'];  // need ["c", "d"] 
Professor Asked on October 27, 2020 in Java Script.
Add Comment
25 Answer(s)

    Is there a way to return the difference between two arrays in JavaScript?

    For example:

    var a1 = ['a', 'b']; var a2 = ['a', 'b', 'c', 'd'];  // need ["c", "d"] 
    Professor Answered on October 27, 2020.
    Add Comment

      Is there a way to return the difference between two arrays in JavaScript?

      For example:

      var a1 = ['a', 'b']; var a2 = ['a', 'b', 'c', 'd'];  // need ["c", "d"] 
      Professor Answered on October 27, 2020.
      Add Comment

        Is there a way to return the difference between two arrays in JavaScript?

        For example:

        var a1 = ['a', 'b']; var a2 = ['a', 'b', 'c', 'd'];  // need ["c", "d"] 
        Professor Answered on October 27, 2020.
        Add Comment

          Is there a way to return the difference between two arrays in JavaScript?

          For example:

          var a1 = ['a', 'b']; var a2 = ['a', 'b', 'c', 'd'];  // need ["c", "d"] 
          Professor Answered on October 27, 2020.
          Add Comment

            Is there a way to return the difference between two arrays in JavaScript?

            For example:

            var a1 = ['a', 'b']; var a2 = ['a', 'b', 'c', 'd'];  // need ["c", "d"] 
            Professor Answered on October 27, 2020.
            Add Comment

              Is there a way to return the difference between two arrays in JavaScript?

              For example:

              var a1 = ['a', 'b']; var a2 = ['a', 'b', 'c', 'd'];  // need ["c", "d"] 
              Professor Answered on October 27, 2020.
              Add Comment

                Is there a way to return the difference between two arrays in JavaScript?

                For example:

                var a1 = ['a', 'b']; var a2 = ['a', 'b', 'c', 'd'];  // need ["c", "d"] 
                Professor Answered on October 27, 2020.
                Add Comment

                  Is there a way to return the difference between two arrays in JavaScript?

                  For example:

                  var a1 = ['a', 'b']; var a2 = ['a', 'b', 'c', 'd'];  // need ["c", "d"] 
                  Professor Answered on October 27, 2020.
                  Add Comment

                    Is there a way to return the difference between two arrays in JavaScript?

                    For example:

                    var a1 = ['a', 'b']; var a2 = ['a', 'b', 'c', 'd'];  // need ["c", "d"] 
                    Professor Answered on October 27, 2020.
                    Add Comment

                      Is there a way to return the difference between two arrays in JavaScript?

                      For example:

                      var a1 = ['a', 'b']; var a2 = ['a', 'b', 'c', 'd'];  // need ["c", "d"] 
                      Professor Answered on October 27, 2020.
                      Add Comment

                      Your Answer

                      By posting your answer, you agree to the privacy policy and terms of service.