Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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

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 :: mock callback function jest 
Javascript :: javascript this 
Javascript :: js get selected value by id 
Javascript :: lodash remove not in array 
Javascript :: convert timestamp to date js 
Javascript :: react pass object as props 
Javascript :: how to check if string contains substring javascript 
Javascript :: discord.js create channel and get id 
Javascript :: variable in js 
Javascript :: javascript regex all matches match 
Javascript :: 100 day javascript challenge 
Javascript :: javascript fetch 
Javascript :: javascript documentation 
Javascript :: string length js 
Javascript :: how to export default class in javascript 
Javascript :: how to aadd variable in html tag in js 
Javascript :: moment js 
Javascript :: pure component 
Javascript :: view child with directive not working undefined 
Javascript :: Usage rate-limiter 
Javascript :: hincrby nodejs 
Javascript :: how to remove whitespace in javascript 
Javascript :: object.keys javascript 
Javascript :: Loading "cdnify.js" tasks...ERROR 
Javascript :: hover javascript 
Javascript :: jquery autocomplete search 
Javascript :: usememo 
Javascript :: javascript create date object for midnight for a timezone 
Javascript :: return js 
Javascript :: javascript rest parameters vs spread operator 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =