How to check whether an array is a sub array of another array in Javascript

Below code snippet can be used to find whether an array is a sub array of another array in JavaScript

Results :

 

  • Eugeny Kozhanov

    It’s useful for me. Thanks!

  • Santiago Piria

    isSubArray([12, 12, 12, 12, 24], [12, 24]);

    returns true and it should be false.
    I suggest possibly copying the array and then removing the item from the array at every for iteration. That way you make sure you have equal amounts of each element.

    • sriram subramanian

      yes, this is valid only for unique elements in the array