Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js compare lists

// compare two arrays where order might differ
const array1 = [1,2,3,4,5];
const array2 = [3,4,1,2,5];

const compareArrays = (array1, array2) => {
  return (
    array1.length === array2.length && 
    array1.every((el) => array2.includes(el));
  );
};

compareArrays(array1, array2); // true
Comment

comparing two arrays in javascript

const arr1 = [1, 2, 3];
const arr2 = [1, 3, 3];

if (arr1.length !== arr2.length) return console.log("false");
for (let i = 0; i < arr1.length; i++) {
    for (let j = 0; j < arr2.length; j++) {
        if (arr1[i] === arr2[j]) {
            console.log("yes match", arr1[i], arr2[j]);
            continue;
        }
        console.log("no match", arr1[i], arr2[j]);
    }
}
Comment

compare two array in javascript

let arr1 = [1, 4, 7, 4, 2, 3];
let arr2 = [1, 2, 3, 4, 7, 18];

const is_same = arr1.length == arr2.length &&
  (arr1.every((currElem)=>{
    if(arr2.indexOf(currElem)> -1){
      return (currElem == arr2[arr2.indexOf(currElem)]);
    }return false
  })
)
console.log(is_same)
Comment

Comparing two lists in Javascript

const equals = (a, b) => JSON.stringify(a) === JSON.stringify(b);

const a = [1, 2, 3];
const b = [1, 2, 3];

equals(a, b); // true
Comment

PREVIOUS NEXT
Code Example
Javascript :: MongooseError: Operation `users.insertOne()` buffering timed out after 10000ms node js 
Javascript :: how to pass token in laravel in jquery ajax 
Javascript :: como saber si un checkbox esta seleccionado en jquery 
Javascript :: add an image to a div with javascript 
Javascript :: javascript format number with commas 
Javascript :: nestjs Built-in HTTP exceptions 
Javascript :: phpmyadmin is not working in ubuntu 20.04 
Javascript :: array sort by alphabetical javascript 
Javascript :: react check if focused 
Javascript :: js redirect page 
Javascript :: javascript document redirect 
Javascript :: render html in node js 
Javascript :: select first 3 letters js 
Javascript :: iso date javascript 
Javascript :: qrcode.js 
Javascript :: props reactjs link 
Javascript :: hello world in jsp 
Javascript :: javascript ip 
Javascript :: discord js setinterval 
Javascript :: get input value in react using hooks 
Javascript :: hide and show in angular 8 
Javascript :: declaration vue 3 variables 
Javascript :: set a previous year to the current date in javascript 
Javascript :: javascript explode 
Javascript :: javascript remove a specific item from an array 
Javascript :: create a category discord.js 
Javascript :: postman test save token 
Javascript :: remove first char javascript 
Javascript :: express js server 
Javascript :: Detecting a mobile browser 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =