Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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)
Source by www.30secondsofcode.org #
 
PREVIOUS NEXT
Tagged: #compare #array #javascript
ADD COMMENT
Topic
Name
8+6 =