Having trouble converting an object's property to lowercase? Here is the issue:
The object story
has a property named status
. The status can be "Vacant", "Occupied", or something else. To simplify it for admins, I want them to enter "vacant" instead of having to worry about capitalization. Even though the status displays properly, that's not my main concern.
I have an if statement:
$.each(story, function(i){
if(story[i].status == "vacant"){
showVacant(i-1);
} else if(story[i].status == "occupied"){
showOccupied(i-1);
} else if(story[i].status == "feature"){
showFeatured(i-1);
} else {
showVacant(i-1);
}
});
I attempted using toLowerCase();
in the if statement:
if(story[i].status.toLowerCase() == "vacant"){
But it resulted in the error
Cannot read property 'toLowerCase' of undefined
. I also tried setting it as a variable using .toString()
first:
myStatus = story[i].status.toString();
if(myStatus.toLowerCase() == "vacant"){
This, however, led to the console error
Cannot read property 'toString' of undefined
How can I ensure that the strings are consistently lowercase while executing this statement?