Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

check if 2 arrays are equal javascript

const a = [1, 2, 3];
const b = [4, 5, 6];
const c = [1, 2, 3];

function arrayEquals(a, b) {
  return Array.isArray(a) &&
    Array.isArray(b) &&
    a.length === b.length &&
    a.every((val, index) => val === b[index]);
}

arrayEquals(a, b); // false
arrayEquals(a, c); // true
Comment

check if array has same values javascript

const allEqual = arr => arr.every(v => v === arr[0]);
allEqual([1,1,1,1]);  // true
Comment

Easy Way to Check if 2 Arrays are Equal in JavaScript

const d = [1,2,4,5,6];
const c = [1,2,4,5,6];

if (JSON.stringify(d) === JSON.stringify(c)) console.log('Equal!');
Comment

javascript check if two arrays contain same values

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

check if two array contains the same values js, array

const areEqual = (arr1, arr2) =>
  arr1.sort().join(',') === arr2.sort().join(',');
const arr1 = [1, 2, 3, 4];
const arr2 = [3, 4, 1, 2];
const arr3 = [1, 2, 3];
console.log(areEqual(arr1, arr2)); // true
console.log(areEqual(arr1, arr3)); // false
Comment

how to check two different length array values are equal in javascript

var a = [2, 4, 10];
var b = [1, 4];

var newArray = [];

for (var i = 0; i < a.length; i++) {
    // we want to know if a[i] is found in b
    var match = false; // we haven't found it yet
    for (var j = 0; j < b.length; j++) {
        if (a[i] == b[j]) {
            // we have found a[i] in b, so we can stop searching
            match = true;
            break;
        }
        // if we never find a[i] in b, the for loop will simply end,
        // and match will remain false
    }
    // add a[i] to newArray only if we didn't find a match.
    if (!match) {
        newArray.push(a[i]);
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: import bootstrap css and js file in react 
Javascript :: Sort to reverse from an array in javascript 
Javascript :: string to title case javascript 
Javascript :: use regex to get urls from string 
Javascript :: react native image source local file 
Javascript :: today in moment 
Javascript :: jq object to dom object convert 
Javascript :: how to make jtextarea scrollable 
Javascript :: javascript switch 
Javascript :: Javascript convert html entity to string 
Javascript :: JAVASCRIPT ARRRAY LOOP BACKWARDS 
Javascript :: js code to remove class 
Javascript :: responsive grid using antd 
Javascript :: js delete all array items 
Javascript :: json get key 
Javascript :: react native callback function uses default state value 
Javascript :: javascript transpose rows to columns 
Javascript :: xml http request 
Javascript :: how to print line break in javascript 
Javascript :: vue.js function to always uppercase when the client input lowercase 
Javascript :: get express variable 
Javascript :: material ui textfield error 
Javascript :: javascript set element width 
Javascript :: splidejs pause 
Javascript :: httpclientmodule is not an angular module 
Javascript :: jquery confirm dialog 
Javascript :: javascript synchronous wait 
Javascript :: js remove special characters 
Javascript :: how to convert to one decimal place javascript 
Javascript :: how to push only unique values in array in javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =