Is possible to do a regex match on an array to find all the items containing certain letters?
My array is:
var myArray = [
"move",
"mind",
"mouse",
"mountain",
"melon"
];
I need to find all items containing the letters: "mo", using a regex match like this:
/mo\w+/igm
To output these words: 'move', 'mouse', 'mountain'...
I've tried this, but does not work properly, it outputs only one item..
Array.prototype.MatchInArray = function(value){
var i;
for (i=0; i < this.length; i++){
if (this[i].match(value)){
return this[i];
}
}
return false;
};
console.log(myArray.MatchInArray(/mo/g));