Linked Questions
77 questions linked to/from How to check if two arrays are equal with JavaScript?
1573
votes
57
answers
1.9m
views
How to compare arrays in JavaScript?
I'd like to compare two arrays... ideally, efficiently. Nothing fancy, just true if they are identical, and false if not. Not surprisingly, the comparison operator doesn't seem to work.
var a1 = [1,2,...
88
votes
2
answers
120k
views
How to check identical array in most efficient way? [duplicate]
I want to check if the two arrays are identical
(not content wise, but in exact order).
For example:
array1 = [1,2,3,4,5]
array2 = [1,2,3,4,5]
array3 = [3,5,1,2,4]
Array 1 and 2 are identical but ...
-1
votes
3
answers
4k
views
How can I check that two array are equal or not? [duplicate]
I am trying to compare two arrays are they equal or not. I am breaking the array a and finally storing them into two different arrays b and c. At last, I am checking the array b and c in the console.
...
0
votes
2
answers
611
views
Why mapping an array using the same function return in different objects? [duplicate]
I want to know why v.map(...) is not equal to v.map(...) using the same function to do the map
var v = [1,2,3,4,5]
v.map(function(a) {return a+1}) === v.map(function(a) { return a+1;})
Running this ...
-3
votes
3
answers
309
views
Why "123".split('') is not equal to [1, 2, 3].join('').split('') [duplicate]
This appears as a very basic question, but couldn't find any explanations on SO.
Consider this:
var arr = [1, 2, 3];
var str = "123";
function compare(){
return arr.join('').split('') ===...
0
votes
3
answers
330
views
Why can't arrays be compared with === in Javascript? [duplicate]
Why isn't this code correctly pushing words to the answer array? When I change the loop to:
for (var k in testDict) {
console.log(testDict[k].split("").sort());
}
it correctly prints ...
0
votes
2
answers
126
views
Why could I compare two strings with "==" but not two arrays of chars? [duplicate]
For example:
var one = ['H', 'i'];
var two = ['H', 'i'];
(one == two) returns false
but
(one.join('') == two.join('')) returns true
Why is that?
0
votes
0
answers
111
views
Tic Tac Toe winning condition in JavaScript [duplicate]
I have kinda weird problem.
I need to make a Tic Tac Toe game for my school project. The board is resizable (e.g. 5x5, 7x7, 12x12) and I want to just check if the first row is filled with circles or ...
0
votes
0
answers
107
views
My == isn't working [duplicate]
I've tried everything. Hours later... I found out the basic == statement isn't working
Here's the code
console.log('The from1 section', from1.section);
console.log('The sender1 section', sender1....
0
votes
1
answer
78
views
Basic anagram function [duplicate]
Hi this is probably an easy question. So I want to make a basic anagram function in Javascript.
The following snippet does not work
anagrams = (phraseOne, phraseTwo) => {
if (phraseOne.split("...
0
votes
1
answer
57
views
Intersect 2 arrays jQuery [duplicate]
Is there a way I can determine the intersection between 2 arrays where the indexing is different, like this:
a1 = ["a", "b"]
a2 = ["b", "a"]
/* a1 == a2 should return true */
and of course,
a1 = ["...
0
votes
0
answers
51
views
String.prototype.split() return a strange array object [duplicate]
I want to find out what is the value of empty which is contructed by "".split("\n").
Here is my trial of finding it.
var empty = "";
empty = empty.split("\n");
console.log("Is empty's length ...
0
votes
0
answers
37
views
Compare array differences by key [duplicate]
I have two arrays with similar values, but arranged in different keys, example:
var array1 = [1, 2, 3, 4, 5];
var array2 = [3, 2, 1, 4, 5];
They are equal in value, but not in key order. Other ...
1035
votes
77
answers
984k
views
How can I determine equality for two JavaScript objects?
A strict equality operator will tell you if two object types are equal. However, is there a way to tell if two objects are equal, much like the hash code value in Java?
Stack Overflow question Is ...
1729
votes
12
answers
373k
views
Differences between Lodash and Underscore.js [closed]
Why would someone prefer either the Lodash or Underscore.js utility library over the other?
Lodash seems to be a drop-in replacement for underscore, the latter having been around longer.
I think both ...