Проблема со сравнением двух строк в Angular - 6 - PullRequest
0 голосов
/ 27 ноября 2018

Я пытаюсь создать оператор 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")
       }

Java script

[РЕДАКТИРОВАТЬ], когда я вручную сравниваю два значения, результат правильный

 if( 'נובמבר 2018' !== 'נובמבר 2018') {
         console.log("The strings are different")

       } else {
        console.log("The strings are the same")
       } 

enter image description here

[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")
   }
})

enter image description here

[Edit3]

Я преобразовал всю строку в массив, как предложил пользователь @ConnorsFan, иэто то, что подошло.Сумасшедший ..

      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")
       }
    })

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...