Example taken from MDN webdocs
var paragraph = 'The quick brown fox jumps over the lazy dog. It barked.';
var regex = /[A-Z]/g;
var found = paragraph.match(regex);
console.log(found); // will return an array of matches and returns null when nothing matches.
Would like to know reasoning behind returning null instead of an Empty Array when nothing matches?
That's how String.prototype.match
is defined in the EcmaScript standard
In short: if nothing matches - it returns null
by the standard.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments