javascript - Why a null result is freezing the script and how to avoid it? -


when use below code:

if(string.match(/td>0/g).length == 8) {     /*do something*/ } 

and no /td>0/ matched, returns null result prevents script below executing.

i know why code freezing, , how avoid , find solution or alternative .match() ?

try this(more recommended):

var matching=string.match(/td>0/g); if( matching != null && matching.length === 8) {     /*do something*/ } 

use === instead of ==.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -