-9

I have got two sets of data:

var array = ["one" , "two" , "three" , "Four" , "Five"];

var T1 = "One" ;
var T2 = "two" ;
var T3 = "three" ;
var T4 = "Four" ;
var T5 = "Five" ;

I want to check the order of data in both sets, I was trying this way:

if(T1==array[0] && T2==array[1] && T3 ==array[2] && T4==array[3] && T5==array[4])
{
    alert('Yes');
}

else
{
    alert('No');
}

But i'm getting alert as "No".

Could you please let me know how to resolve this?

http://jsfiddle.net/85utz097/

Komal12
  • 3,340
  • 4
  • 16
  • 25
Pawan
  • 31,545
  • 102
  • 256
  • 434
  • 9
    `"One"` and `"one"` are not the same string. See http://jsfiddle.net/85utz097/2/ Did you want the comparison to be case-insensitive? If that's the case, see http://stackoverflow.com/questions/2140627/javascript-case-insensitive-string-comparison for example. – Matt Burland Apr 22 '15 at 14:54
  • Try `T1.toUpperCase()==array[0].toUpperCase()` if you don't need to be case sensitive. – Cobote Apr 22 '15 at 14:59

4 Answers4

1

Javascript is case-sensitive, therefore "One" is not the same as "one" in your array.

Jonathan
  • 11
  • 1
0

You are getting "No" because

One != one

Change this:

var T1 = "one" ;

and you will get a "YES"!!

Check the DEMO

kapantzak
  • 11,610
  • 4
  • 39
  • 61
0

== is case sensitive and your T1 is "One" and should be "one"

Hope it helps :)

Pipo
  • 193
  • 1
  • 1
  • 9
0

Try T1.toUpperCase()==array[0].toUpperCase() or T1.toLowerCase()==array[0].toLowerCase()

see JSFIDDLE

Karups
  • 187
  • 1
  • 2
  • 11