3 回答
TA贡献1772条经验 获得超6个赞
// First time
var a = [1, 2, 3];
var b = [1, 2, 3];
var c = "1,2,3";
a == c; // true
b == c; // true
a == b; // false
//Second time
console.log(a == c);
console.log(b == c);
console.log(a == b);
a = [1, 2, 3];
b = [a, 2, 3];
c = "1, 2, 3";
console.log(a == c); //false
console.log(b == c); //false
console.log(a == b); //false
第二组看起来像这样:
a = [1, 2, 3];
b = [[1,2,3],2,3]; -> Jagged Array;
c = "1,2,3"
TA贡献1798条经验 获得超3个赞
b = [1, 2, 3]; // first b = [a, 2, 3]; // second
数组的第一个元素不同
ps避免'=='并在生产中使用'==='。
TA贡献1794条经验 获得超7个赞
您第二次执行的所有值都是错误的,因为没有一个值是相等的。
var c = "1,2,3" 与 c = "1, 2, 3" 不同,因为第二个字符串中有空格。
var b = [1, 2, 3] 与 b = [a, 2, 3] 不同,因为第二个数组中的第一个元素不同。
试试下面的代码
// First time
var a = [1, 2, 3];
var b = [1, 2, 3];
var c = "1,2,3";
a == c;
b == c;
a == b;
//Second time
console.log(a == c);
console.log(b == c);
console.log(a == b);
a = [1, 2, 3];
b = [1, 2, 3];
c = "1,2,3";
console.log(a == c);
console.log(b == c);
console.log(a == b);
添加回答
举报