Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,933 questions

51,870 answers

573 users

How to compare two arrays in Node.js

3 Answers

0 votes
let arr1 = [1, 2, 5, 9];
let arr2 = [1, 2, 5, 9];
 
let equal = JSON.stringify(arr1) === JSON.stringify(arr2);
 
console.log(equal);
 
 
     
     
/*
run:
     
true
     
*/

 



answered Jan 25, 2022 by avibootz
0 votes
let arr1 = [1, 2, 5, 9, 8];
let arr2 = [1, 2, 5, 9, 8];
 
let equal = arr1.toString() === arr2.toString();
 
console.log(equal);
 
 
     
     
/*
run:
     
true
     
*/

 



answered Jan 25, 2022 by avibootz
0 votes
let arr1 = [1, 2, 5, 9, "a"];
let arr2 = [1, 2, 5, 9, "a"];
  
if (arr1.length == arr2.length &&
    arr1.every(function(element, i) {
        return element === arr2[i];
    })) {
   console.log(true);
} else {
   console.log(false);
}
 
  
      
      
/*
run:
      
true
      
*/

 



answered Jan 25, 2022 by avibootz
edited Jan 25, 2022 by avibootz

Related questions

1 answer 101 views
1 answer 91 views
2 answers 140 views
2 answers 132 views
132 views asked Mar 12, 2022 by avibootz
1 answer 62 views
1 answer 87 views
...