Sunday, 18 August 2013

Compare strings to see if they are identical

Compare strings to see if they are identical

I would like to loop through a set of strings and see if they are all
identical to one another. If all of the strings being looped through are
identical, I would like to run one function. If they are not, run another
function.
$(".variationPrice").each(function(){
var price = $(this).text();
if(price == price){
allMatch();
} else{
notMatch();
}
});
Another words, if we had the following data, it would run allMatch(): $55,
$55, $55
If we had the following data, it would run noMatch(): $55, $45, $55
The above code does not work but acts as a starting place. In the above
code, price would always match price. I need to figure out a way to store
the first price in a variable and compare all results after to the
initial. What is a good way of comparing strings via jquery / javascript?

No comments:

Post a Comment