Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js compare values of two arrays

const a = ['Left', 'Right'];
const b = ['Right', 'Left'];

//	true if a and b contain the same values
//	false otherwise
const c = a.sort().join(',') === b.sort().join(',');
Comment

javascript Compare two arrays regardless of order

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

// Examples
isEqual([1, 2, 3], [1, 2, 3]);      // true
isEqual([1, 2, 3], [1, '2', 3]);    // false
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

how to compare two arrays javascript

function arraysAreIdentical(arr1, arr2){
    if (arr1.length !== arr2.length) return false;
    for (var i = 0, len = arr1.length; i < len; i++){
        if (arr1[i] !== arr2[i]){
            return false;
        }
    }
    return true; 
}
Comment

compare between two arrays javascript

const equals = (a, b) => JSON.stringify(a) === JSON.stringify(b);
let arr1 = ['1','2'];
let arr2 = ['1','2'];
equals(arr1,arr2)//this return false , if not equal then its return false
Comment

PREVIOUS NEXT
Code Example
Javascript :: sum all values of an array 
Javascript :: js get text from html string 
Javascript :: javascript emit event 
Javascript :: insert element in specific index javascript 
Javascript :: javascript parse date dd/mm/yyyy hh:mm:ss 
Javascript :: countdown javascript 
Javascript :: javascript fromEntries 
Javascript :: replace each string by another string javascript 
Javascript :: express command not found mac 
Javascript :: javascript arrow function 
Javascript :: new line in javascript alert 
Javascript :: add class in element on scroll 
Javascript :: select2 find option by text 
Javascript :: string interpolation in javascript 
Javascript :: js encryption 
Javascript :: largest and smallest number in an array 1-100 javascript 
Javascript :: filter json array by key in angular 9 
Javascript :: check if number is float 
Javascript :: Javascript stringify with functions 
Javascript :: setting usestate to prop 
Javascript :: Get the index of an Object in an Array in JavaScript 
Javascript :: axios get image 
Javascript :: merge sort algorithm in javascript 
Javascript :: generators in javascript 
Javascript :: javascript add event listenner for multiple events 
Javascript :: javascript sleep 1 second” is a pretty common code problem that people search ;-) 
Javascript :: regex quantifiers 
Javascript :: clearing cookie in js 
Javascript :: round to decimal javascript 
Javascript :: how to deep copy an object in javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =