Checking If Null
This is a very simple question, but because I've only been doing this language for a week, the answer has not come to me. An error occurs in between the following two lines, becaus
Solution 1:
Like this:
var Regex = /<span class="currency-robux">([\d,]+)<\/span>/;
var PriceSelling = data.match(Regex);
PriceSelling = PriceSelling ? PriceSelling[1] : '';
if (PriceSelling.length < 1) {
alert('Nothing!');
}
Solution 2:
You could either do it in two steps:
var result = data.match(Regex);
var PriceSelling = result != null ? result[1] : undefined;
or use the OR operator to use an empty array as the default result:
var PriceSelling = (data.match(Regex) || [])[1];
Post a Comment for "Checking If Null"