showing results for - "js compare lists"
Marley
16 Nov 2020
1// compare two arrays where order might differ
2const array1 = [1,2,3,4,5];
3const array2 = [3,4,1,2,5];
4
5const compareArrays = (array1, array2) => {
6  return (
7    array1.length === array2.length && 
8    array1.every((el) => array2.includes(el));
9  );
10};
11
12compareArrays(array1, array2); // true
13
Magnus
10 Nov 2019
1Array.prototype.equals = function(arr2) {
2  return (
3    this.length === arr2.length &&
4    this.every((value, index) => value === arr2[index])
5  );
6};
7
8[1, 2, 3].equals([1, 2, 3]);	// true
9[1, 2, 3].equals([3, 6, 4, 2]);	// false
Lorenzo
01 Jun 2017
1// To compare arrays (or any other object):
2// Simple Array Example:
3const array1 = ['potato', 'banana', 'soup']
4const array2 = ['potato', 'orange', 'soup']
5
6array1 === array2;
7// Returns false due to referential equality
8JSON.stringify(array1) === JSON.stringify(array2);
9// Returns true 
10
11
12// Another Example:
13const deepArray1 = [{test: 'dummy'}, [['woo', 'ya'], 'weird']]
14const deepArray2 = [{test: 'dummy'}, [['woo', 'ya'], 'weird']]
15
16deepArray1 === deepArray2;
17// Returns false due to referential equality
18JSON.stringify(deepArray1) === JSON.stringify(deepArray2);
19// Returns true
20
21
queries leading to this page
compare arrays javascript es6compare 2 list javascriptequating two arrays in jsjavascript compare arrays of jsonbest way to compare two arrays javascriptnode compare arraysjavascript how to compare arrayshow to compare array elements in javascript with given valuetwo array value compare in javascriptcomparing arrays in js compare javascript array functionscompare with array jsjs compare equality of arrayscompare values in an array javascriptjavascript compare to arrays and its valuesjs array elements comparejavascript compare arrayscompare all array with each other javascriptcompare array values javascriptjs compare two numsbers in an arraycomparing two arrays react jscheck array equal javascriptcompare 2 string arrays in javascriptcompare and return a value in one array javascriptmatch between 2 arrays in javascriptjavascript two array equalcompare two array in javascriptcompare two lists javascriptes6 compare arrayjavascript compare vectorjs compare 2 arrayscompare and return a value in array javascriptcompare var with array jsgetting equals value in two array javascriptjavascript function to compare one array item in another array without using forjavasacript compare values againsty arrayconfront value in if arrayaaray element in array compare javascriptjs compare arrays equalhow to compare single value with array in javascriptjs compare to arrayshow to compare elements within an array javascripttwo array compare 25 compare arrays using set javascriptcompering inside an array javascriptcompare javascript array valuescomparing two arrays in jscompare elements of the same array javascriptcompare array element javascripthow to compare two elements in one array in javascripthow to compare two elements in one array in javescripthow to compare trwo array items in javascriptcomparing arrays jsjavascript comparing arrayscompare whether the data inside the array is the sametest array in js deep or strictcompare element in array javascriptarray comparison jswhy comparing 2 arrays in javascriptcompare length of 2 elements javascriptjavascript arrays comparisonangular array equals arraycompare value against arrayjs array compare elementshow to compare array of strings in javascriptcompare value with value of array jshow to compare items in an array javascriptcan you compare arrays with length javascriptjs compare elements in arraycomparing two lists javascripthow to compare two list in javascripthow to compare array in javascriptcompare to array javascriptcomparing arrays javascriptcompare values of array elements in javascripthow to compare two string array in javascriptcompare element in array typescript how does it workcompare list in jscompare arrays javascirptjavascriipt compare two arraysmethod for comparing elements of same array javascirptcompare value from array javascripthow to compare array content in java scriptcompare two array value in javascriptmethod to compare 2 arrays in jscomparing items in an array javascriptcompare value number of array javascriptcompare 2 array javascriptjavascript compare two arraylistcompare 2 arrays in jscompare all array jscompare array of value with one var in jsjs array compare valuesjs compare two string if equal return only the firstjavascro 5bt compare 2 arrayscompare 2 arrays values javascript javascript compares two arrayshow to compare array positions javascripthow to compare two array javascriptjavascript compare elements in two arrayshow to see compare two array jsjs equality of arraysjavascript string arraay comparejavascript comparison array and array list not workingcomparing arrayhow to compare 3 arrays in javascriptcompare objects in array javascriptcompare element to other elements in array javascripthow to compare an array to an array of arrays in javascripthow to compare values of two arrays in javascriptcompare array elements in javascriptcomparing array in jscompare two arrays in javascripthow to compare two array in jshow to link two array values are equal in javascripttow list compare javascriptcompare array with array jscompare arrays javascriptcompare json lists of strings jshow to compare arrays in javascriptjavascript compare 2 arrayshow to compare array items jscompare array string javascripthow i compare two arrays in jscompare two string array in javascriptcompare 2 arrays in javascriptcompare arrays js es6compare if string value i sgreater in array jsjavascript how to compare two arrayshow to compare array elements individially in javascriptcomparing 2 arrays javascriptarray compare function in javascriptcompare two array jshow to take 2 elements of array in javascript and comparecompare with code inside array javascripthow to compare two indecies next to each other in an array jscompare 22elements 22 of the same array javascripthow to compare array and string in javascriptcomparing numbers in an array javascripthow to compare an array in an if statement jsfastest way to compare two arrays javascriptcompare elements in two arrays two arrays javascriptjavascript comparing string arrays for equalitycompare if two arrays are equal javascriptcompare array value in javascriptcompare 2 arrays in javascript with array methodsjs compare arrayscompare numbers in arrays javascriptcheck 2 elements inm array jshow to compare array elements js2 array comparejavascript compare elements arrayjavascript compare values in any of arrayhowt to comapre two arrays in javascripthow to compare arraycomparing array of objects in jshw to compare two arrays javascripthow to compare arrays jsjs compare array contentsjs array comparisonarray compare elements javascriptcheck equality of two arrays in javascriptjavascript array comparisoncompare value in array jscompare two large arrays of strings and get mutual values jscompare two array value one by one js compare elements in one arrayhow to compare an array to itself in javascripthow to compare 2 lists jscheck two arrays are equal javascriptcompare 3 array at index for values javascriptfunction how to compare elements in an arrayhow to compare array elements in javascripthow to compare an item to arrays in javascriptjavascript comparing array elementsarray compare javascriptjavascript for of compare two arraysjavascript assert two arrays deeparray comparison jscompare elements in list jscompare two array javascript return false if diffirentcompare arrays in javascriptjavascript compare two arrays sortedtwo array value compare in jsjavascript compare two arrays are equaljs compare array in arrayhow to compare list with array in javascriptjs compare arrays ifcompare arrays nodejsarray comparsion javascripthow we compare two arraycompare array methods javscriptjavascript compare all contents of an arraycompare arraysequality array javascriptcompare elements array javascriptjavascript how to compare array valuematch similarities in array javascriptarray values compare in javascriptarray element comparejs comparing arraycomparing list in javascripthow to compare array to array in javascriptcompare two arrays jsjs comparing 2 array datajavascript compare lsit of arraycompare array of strings javascriptcompare two arrays of numbers javascriptjavascript compare function arraycomparing two arrays in javascriptjavascript array compare two arrayscompare numbers js array es6each and every letter name comparison in array node jsjs compare values in arraycompare string with array javascripthow to compare attay in typescriptjs compare array valueshow to compare two arrays in javascript demohow to compair araay value in jshow to compare values in an array javascriptcomparing two arrays elements javascriptwhy array in javascript is equal to stringjs compare two arrays of stringshow to compare two arrays in javascript if conditiontypescript string array comparisonhow to compare lists jshow to compare elements of an array in javascriptcompare two array inline javascriptcompare array to array javascriptcompare number with an array javascriptcompare to arrays javascriptjavascript comparing two listscompare elements in one array javascriptcompare array valueshow to compare two arrays in javascriptcomparing with arrays in jsequate two arrays jscomparison of arrays jshow to compare arrays javascript with loopshow to compare array elements without knowing them jscompare two array elements javascriptjavascript is string equal to array of string eachcompating size using every javascirptcompare elements of trwo arrays in jscompare values of array in javascriptcompare contents of array javascriptjs 2 array comparejavascript array element comparecompare two json array javascripttypescript two arrays equalcompare list javascriptcompare the values in one array typescriptcomparing elements in array using javascriptjs compare each element two arraysjavascript compare two array of objectsjavascript compare items in arraycomparation arrays jsjavascript compare one element with rest of arrayhow to compare each element in an array in javascripthow to compare two arrays javascripttwo array compare in javascriptcompare a array javascript numberwhat happens if you compare a variable to an array if statement jsjavascript compare equivalent arrayjavascript compare two arrajs array compare function based on listcompare lists jvascirptcompare elements of one array javascripthow to compare value of arrayjs array equal to arrayfind equal strings array node isequalhow compare two list in javascripthow to compare elements of two same size arrays in javascriptcompare in multiple array and return objects in javascripthow to compare two arrays of strings in jscompare array values jsjavascript compare arrays array is in smallerjavacript compare all array value withcompare two choices taken from the same array javascriptcompare elements of arrayhow to compare two arrays elements in javascripthow to compare an array javascriptcompare 3 arrays if first index is equal javascriptjavascript equalize two arrays to each otherhow can compare value with array in javascripthow to compare 2 arrayscomparing two arrays in javascript fuctionhow to compare values in an array in javascriptcomparing array emements in jswhy cant you compare strings in an array javascriptjavascript array compare functionhow to compare a item of a array to var in javascriptcompare two arraus are same or not jshow to compare array of array in javascriptjavascript compare values in arrayhow to check if two arrays are equal javascriptjs array compare arraycomparing two arrays javascriptcompare array values in typescriptcreate a bool array from array comparison js comparing elements of an array in java scriptcompare in js arrayarray equality jstwo arrays need to compare javascriptcompare array item jscompare two arraycompare elements in array jscompare items in array javascriptjavascript two array comparecompare strings in an array javascript code using 2 for loopsarray comparison javascriptcompare array value with string in javascriptjavascript loop an array and compare equaljs compare strings in array samecomparing array values in javascript json stringifycompare js arrayscompare the elements in two arrays jshow to compare two arrays in jscompare array in jshow to compare array length in javascriptarray compare array javascriptcompare arrays jsjavascript compare arrays of jsonses6 compare arraysjs compare array elementshow to compare and find 28 29 array with array in javascriptcomparing two array 27s jscomparing arrays in javascriptjs can you compare arraysjs compare array by valuecompares a number with each value in the array in javascripthow to compare elements inside an array javascriptcompare all array element jsnode js compare arrays elementshow to compare two array values in javascriptcomparing array javascriptcomparing 2 arrays javascript and make 3rd arraycompare 2 array jsjavascript comparing characters from different arraysjavascript comparison between 2 arraycompare 2 arrays in a functionhow to compare if a new item was added to an array javascriptjs compare array and arraycheck 2 arrays with somecompare string in array javascripttypescript compare 2 string arraysjavascript array compare all elementjavascript array if string is samehow to compare all elements in an array javascriptcompare list of arrays javascripttypescript compare arraycompare array element wirh item javascripthow compare positions of two arrays javascriptjs compare array sortjs compare arry of arrayjavascript comparearrays 28 29compare elements in list javascriptcompare to array in javascriptcompare string with array in javascriptcompare array of value with one value in jsjavascript compare arrays 5cstring array compare javascripthow to compare array of element in javascriptcompare one array to another javascriptarray element compare javascriptjavascript compare 2 arrays methodjs compare array equalitycompare to arrays javascript valuescompare set of numbers in two arrays javascripttwo array comparison in javascripthow to compare array elements with string in javascrcompare arrays javascript methodscomparing items in an array in javascriptjs compare 1 element with arrayjavascript array find function to compare valuejs compare array values are samecompare arrays element javascriptcompare array length javascriptcompare string arrays in javascripthow to match 2 arrays in javascriptcompare two array inline in javascriptjs compare arrays for equalityjs compare array to arrayhow to compare a string with arrays in jscompare two array elements in javascripthow to compare to arrays in javascriptjavascript assert two arraysarray compare valuearray equals javascript es6javascript list comparehow to compare two array elements in javascriptjavascript arrays compare elementsarray deep equal javascriptcan you use 3d 3d to compare two arrays in javascriptjs compare value arraycompare array elements javascriptcompare two arrays in java script with sorthow to check equality of two string arrays in javascriptshow equel array in jsnodejs compare array with stringcompare two list in jscomparing elements in the arrayhow to compare two arrays jsmatch arrays javascripthow to compare a big value in two array values in javascriptjavascript compare string arrayscompare two array javascriptbest way to compare two arrays in javascriptjs compare arraycompare each array javascriptcomparing two arrays javascript is greater thancompare array javascripcompare prev arrray jshow to compare value with arraycompare string in array jsjavascript compare arrays 28 29js compare two arrayscompare an items against an array javascriptlist equal in javascripthow does js compare arraysjs array comparearray elements compare javascripthow to compare items in array jshow to compare when new element in array javascriptjavascript 2 array comparecompare two array jsjavascript compare two arraysjavascript compare two array elementsmethod to compare arrays javascriptcompare two arrays of strings javascripthow to compare array values in javascriptarray equality javascriptarray of number js comparearray value comparison in javascriptcomparing text in arrays not working javascriptcompare array elements values javascriptcompare value array jsjs comparing string arraysjavascript array comparecompare array index javascripthow do i compare two arrys in jscomparing elemnts in an array javascripthow to compare elements in an array jshow to compare to arrays jscompare values in array javascriptjs compare listscompare between 2 array tsjavascript compare to arrayscompare values in array includes javascriptjavascript compare two arrays valueshow to compare two arra in jscompare lists javascriptcompare whole array between twocompare array to larger array return valueshow to do matrix compare without for loop in node jscompare two array elements in jsjs array equal comparisonjs array equal checkjs compare arrays existingarray comparison in jsjavacript array compare valuescomparing two arrays jscompare two string inside of an array javascripthow to compare different arrays in javascripthow to compare arrays in javascript 3fjavascript compare two arraycompare array equality injshow to compare all elements in array javascripttypescript compare array elementscompare two array from a in javascriptarray comparing in jshow to compare array es6how to match two arrays in javascriptarray comparison in javascriptcompare two arrays javascriptjs equal between two arraysjavascript compare two array element 27s valuecompare array in javascriptcompare one array to anotehrarray compare elements in javascriptjs compare string of arraycompare values in array javascriptequality of array javascriptnode js compare arrayscompare the array and string in javascriptjs fastest check between 2 listcompare array with string in javascriptjson stringify compare arraycheck array equals javascriptarray compare operation in jswhat is the result if compare two arrays in javascriptjavascript compare array elementscompare two lists jsjavascript one array how to compare two arrays insidecompare two arrays element in javascriptcompare arrays javascript 2b1js compare array of arrayshow to compare values in array jscompere 2 list jshow do you match arrays in javascriptjavascript compare array with string array comparecompare two arrays jscompare two list in tscompare contents of array jsarray value compare in javascripthow to compare values in array javascriptcompare numbers in array javascriptcompare values array javascriptjavascript match 2 elements from separate arrayscompare array javascriptnodejs compare elements in two listsjs compare array with stringhow to compare int arrays in javascriptcompare arrays mdnhow to compare the two array in javascript includeshow to compare arrays of arrays in javascriptcomparing arrays typescriptstring array compare jscompare number with array javascriptcompare 2 array are equal javascripthow to compare one array with another in javascriptcomparing 2 arrays positions in javascriptjs array compare 2 array check if two arrays are equal in jscompare lists in javascriptcompare two fields of same array in javascriptjs compare two values in an array for each valuehow to compare array with array in javascriptnodejs compare two listsjavascript array comparisioncompae arrays javascriptcompare array values javascriptjavascript compare array valuesjavascript to compare two arrayscomapring two arrays in jsjavascript compare arrays array is inside arraycompare two arrays of length javascriptcompare item in array javascriptshallow equald with index of javascripthow to compare array with string in javascriptbest way to compare arrays in javascriptcompare an array with a string javascriptjavascript two arrays comparecompare two array and create new array in javascriptcompare elements of an array javascriptcomparing two lists in javascriptjavascript fastest way to compare two arrayshow to compare 2 arrays javascriptcompare arrays of strings javascriptcomparing numbers in a array javascriptcompare arrays in jscan you 3d 3d 3d two arrays javascriptjavascript array equal to arraycompare two arrays value in javascriptcompare two arrays of strings and check equal in javascriptjavascript typescript compare two arrayscomparaison function array javascriptcompare to array jscompare array values in javascriptcompare array elementsjs compare multiple arrayscompary list values in javascriptcompare elements in an array javascriptarray conpare jsarray comparejavascript array string comparecomapre two array and get the string which is same in both array 2bnodejscomparing 2 arrays in javascriptcompare two arrayshow can i compare array elementshow to compare elements in an array in javascript js function to compare to arrayhow to compare elements in a array jscomparing every element in javascript arraycompare two arrays if both javascriptfunction compare arrays javascriptcompare array value and print same value in javascriptbest way compare arrays javascriptcompare javascript arrayshow to compare const with arraycompare 2 arraysa in jshow to compare two arrays of different data javascriptif 2 value in compared arrays are equal take them out of the arrayhow to compare array values jsjavascript compare elements in arrayhow to compare 2 arrays in javascriptcomapre two arrays javascriptcompare with code array javascriptjs comparte 2 arrayshow to compare elements in array javascriptmatch two array javascriptcompare 2 string arrays in jshow to compare two arrays values in javascriptcomparing array jshow to compare two arrayhow to differentiate array value in if condition in javascriptall array comparison in javascriptcomparing two arrays in javasripthow to compare two array jshow do you compare array values in javascriptcompare function in js array sorrtcompare element arr jsother than includes to copare value inside arraycompare two arrays at once javascriptcompare 2 list of strings in javascriptcompare two strings at each index for same values javascriptjavascript compare arrays i and i 2b1comparing two array elements in javacriptjs best compare listshow to compare between two arraycompare elements two arrays javascriptcomparing array elements in javascriptmatch two array jscompare array valuejs compared two array of objectscomparer deux array javascriptcompare array javascriptcheck two fields are same in arrays javascriptcompare to arrays in javascripttwo arrays compare javascriptjavascript compare array of arrayscompare values js arraysjs comparing arraysjs comparing two arraysjavascript compare listhow to compare 2 arrays having same id in objects in javascriptwhy cant you compare arrays javascripthow to compare javascript arrays for equalityarray compare in jsjavascript compare arrrayscompare arrays of objects javascriptjavascript compare array of objectshow to do array comparison in javascripthow can array and string be same in javascriptcomparing array values jscompare 2 arrays node jsjavascript loop and compare array elementsjs how to compare two arrayshow to compare two values arrays in javascriptcompare two arrays in javascript return vitemshow to compare each element of the array jsarray set comparecomparing an array in jscheck if two arrays have similarities nodejsarrays equality jsarray compare in javascriptarray comparisoncompare two arrays 2b javascripttype check equal array in javascripthow to compare an arrat with a word in javascriptcompare array in arrayjavascript compare arraysscomparing array values in javascriptjavascript compare arrays of strings if have same valueshow to compare the array values in javascripthow to compare to arrays in jsjs compare lists elements in arraycomparing array of string in javascripthow to equal data in to arraycompare two arrays and update javascripthow to compare arrays javascriptcomapring 2 arrays in tsjavascript array compare elementsjavascript comapre arrayscompare array jsjavascript comparing arrays for equalityjavascript compare string values from arrayjavascript compare element in arraycompare 2 arrays jshow to compare 2 array in javascriptjavascript array compare each elementjs array to array comparejs compare value in arrayjavascript compare two arrays regardless of ordercompare value with an arraycompare lists of strings jsnodejs compare arraysjs compare 2 arraycompare array number with value typescriptcompare array with array javascriptcompare array items javascriptarrays compare javascriptcompare 2 arrays javascriptjs compare arrays lengthcompare value with array in javascriptcompare elements of array javascriptcompare two array best method javascriptcompare arrays if is different typescriptcompare array elements jsarray equals jshow to compare two elements of array in javascripthow to compare arrays with stored array in javascriptjavascript compare array with variablescompare 3 arrays javascriptcompare one array elements javascriptjavascript compare arrays for equalityjavascript comparing all characters from one array to anotherarray compare and get datajavascript match 2 string arrayscomparing each value in an array jscompare two lists in jshow can we compare arrays in jshow to compare elements of araay jscompare against array javascripthow to compare two array list in javascriptjavascript compare listsjavascript compare array exactlyjavascript compare array with beforecompare two array in jsjs compare two arraymethod to compare two arrays in javascripthow to compare a value with an array in javascriptjavascript code to compare two arrayscompare two arrays js same sizehow to compare elements of array javascriptcompare two arrays if first index is largerjs compare arrays onlinejavascript compare to arrayhow to compare to array in javascriptarray equals javascriptcompare two arrays in jshow to compare string array in jshow to compare array and array in javascriptcan you compare arrays in javascriptcompare 2 arrays in java scripthow to compare two array in javascriptcompare each value of the array in javascriptarray compare jshow to compare two scalar arrays javascriptcomparing each element in an array javascriptcomparing array based on array elements in javascriptcompare el in js arrayscompare an array of arrayscomparing numbers in a n array javascriptcompare two arrays in javascript w3schoolsjavascript compare 2 arraycompare item in array typescripthow to compare elements in the same array javascriptdata structure read compare two arrays values javascriptarray comparisioncompare two arrays at each index for same values javascriptmethod for comparing array elements javascirptcomparw bwtween to rrays jscompare value in one array javscriptcompare string arrays javascriptjs compare elements arraysjavascript array equalitycompare arrays test jshow to compare two different arrays in javascriptcheck two arrays and return equal javascriptcompare two string array typescriptcompare two json arrays in javascriptcompare arrays and return elements only in one arrayjavascript array compare all elementsjavascript compare element of arrra in arrayhow to compare array on element in javascriptcompare tow arrayscomparing numbers in a javascript array which is biggerjava script two arrays have the exact same elementsjavascript compare array lengthhow to compare two big arrays javascriptstring array compare in jsjs function to compare every 2 elementscompare arraycompare two string arrays typescriptjavascript compare values in arrays functioncompare elements in array javascriptjavascript how to compare value of two arrayscomparing array elements javascriptcompare values inside array javascriptwhen compare to arrays in javascriptcheck array equality javascriptarray and array comparecomparing two array in javascripthow to compare whole array imn java scriptjs compare number arrayarray compare jscompare two arrays values in javascriptjavascript how to compare 2 arrayscompare function for array of arrays jsjavascript compare arrayhow to compare elements in an array javascriptcompare two arrays javascript for compare two arrays for values javascriptcompare if string value is greater in array jsjs arrays comparecomparing arrays elements jshow to compare inside array elements in javascriptcompare 4 arrays jsmatch two array of array jscompare values of two arrays javascripthow to check two array jshow to compare array elements in js find equals strings in a array nodejs compare lists