我试图创建一个if语句,该语句应该比较两个字符串,但是出于相同的原因,某些事情不起作用。
console.log(this.selectedDay.split("/")[2])
console.log(this.selectedMonth)
if( this.selectedMonth !== this.selectedDay.split("/")[2]) {
console.log("The strings are different")
} else {
console.log("The strings are the same")
}
[编辑] 当我手动比较两个值时,结果是正确的
if( 'נובמבר 2018' !== 'נובמבר 2018') {
console.log("The strings are different")
} else {
console.log("The strings are the same")
}
[EDIT2]
将拆分结果分配给VAR
const value1 = this.selectedMonth;
const value2 = this.selectedDay.split("/")[2];
console.log(value1)
console.log(value2)
if( value1 !== value2) {
console.log("The strings are different")
} else {
console.log("The strings are the same")
}
})
[Edit3]
我像用户@ConnorsFan所建议的那样,将所有字符串都转换为Array,这就是结果。疯了。
const value1 = this.selectedMonth;
const value2 = this.selectedDay.split("/")[2];
console.log(value1);
console.log(value2);
console.log(value1.split(""));
console.log(value2.split(""));
if( value1.valueOf() === value2.valueOf()) {
console.log("The strings are the same")
} else {
console.log("The strings are diffrent")
}
})