mardi 28 juillet 2015

How to determine if an array value matches a string in javascript?

Here is what I have.

for (var k = 0; k < 26; k++) {

if (status[k] == "skipped ")
document.write(name[k] + " <span style=\"color:red;\">"+ status[k] +"<\/span><br>")
else 
document.write(name[k] + " <span style=\"color:green;\">"+ status[k] +"<\/span><br>")

}

status[k] is a string and will either contain "skipped " or "checked out " which I am trying to determine using if else. However, regardless of whether the string contains skipped or checked out, it always go resorts to the else statement, so I know for some reason it is failing the check. Basically, how to properly see if status[k] == "skipped " where status is an array of strings.

If I manually set, for example, status[3] = "skipped " then it works properly. However, not when it is stored in the array.

Aucun commentaire:

Enregistrer un commentaire