[javascript] How to compare arrays in JavaScript?

I needed something similar, comparing two arrays containing identifiers but in random order. In my case: "does this array contain at least one identifier from the other list?" The code is quite simple, using the reduce-function.

function hasFullOverlap(listA, listB){ 
   return listA.reduce((allIdsAreFound, _id) => {
         // We return true until an ID has not been found in the other list
          return listB.includes(_id) && allIdsAreFound;
        }, true);
}

if(hasFullOverlap(listA, listB) && hasFullOverlap(listB, listA)){
   // Both lists contain all the values
}

Examples related to javascript

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax

Examples related to arrays

PHP array value passes to next row Use NSInteger as array index How do I show a message in the foreach loop? Objects are not valid as a React child. If you meant to render a collection of children, use an array instead Iterating over arrays in Python 3 Best way to "push" into C# array Sort Array of object by object field in Angular 6 Checking for duplicate strings in JavaScript array what does numpy ndarray shape do? How to round a numpy array?

Examples related to json

Use NSInteger as array index Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) HTTP POST with Json on Body - Flutter/Dart Importing json file in TypeScript json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 190) Angular 5 Service to read local .json file How to import JSON File into a TypeScript file? Use Async/Await with Axios in React.js Uncaught SyntaxError: Unexpected token u in JSON at position 0 how to remove json object key and value.?