How to check if an array is a subset of another array in JavaScript?
<p>Let's say I have two arrays,</p>

<pre><code>var PlayerOne = ['B', 'C', 'A', 'D'];
var PlayerTwo = ['D', 'C'];
</code></pre>

<p>What is the best way to check if arrayTwo is subset of arrayOne using javascript?</p>

<p>The reason: I was trying to sort out the basic logic for a game Tic tac toe, and got stuck in the middle. Here's my code anyway... Thanks heaps!</p>

<pre><code>var TicTacToe = {


  PlayerOne: ['D','A', 'B', 'C'],
  PlayerTwo: [],

  WinOptions: {
      WinOne: ['A', 'B', 'C'],
      WinTwo: ['A', 'D', 'G'],
      WinThree: ['G', 'H', 'I'],
      WinFour: ['C', 'F', 'I'],
      WinFive: ['B', 'E', 'H'],
      WinSix: ['D', 'E', 'F'],
      WinSeven: ['A', 'E', 'I'],
      WinEight: ['C', 'E', 'G']
  },

  WinTicTacToe: function(){

    var WinOptions = this.WinOptions;
    var PlayerOne = this.PlayerOne;
    var PlayerTwo = this.PlayerTwo;
    var Win = [];

    for (var key in WinOptions) {
      var EachWinOptions = WinOptions[key];

        for (var i = 0; i &lt; EachWinOptions.length; i++) {
          if (PlayerOne.includes(EachWinOptions[i])) {
            (got stuck here...)
          }

        }
        // if (PlayerOne.length &lt; WinOptions[key]) {
        //   return false;
        // }
        // if (PlayerTwo.length &lt; WinOptions[key]) {
        //   return false;
        // }
        // 
        // if (PlayerOne === WinOptions[key].sort().join()) {
        //   console.log("PlayerOne has Won!");
        // }
        // if (PlayerTwo === WinOptions[key].sort().join()) {
        //   console.log("PlayerTwo has Won!");
        // } (tried this method but it turned out to be the wrong logic.)
    }
  },


};
TicTacToe.WinTicTacToe();
</code></pre>