var array=[[“The end”,“end the”],[“A the”,“no way”],[“yo man”,“man the”]];
function chkthe(arr){
var result=0;
var exp=/the/gi;
for(var i=0;i<arr.length;i++){
for(var j=0;j<arr[i].length;j++){
//var result=0;
//var exp=/the/gi;
var matc=arr[i][j].match(exp);
if(matc!==null){
result+=matc.length();
}
//result+=(arr[i][j].match(exp)).length();
}
}
return result;
}
console.log(chkthe(array));
Hey guys in the upper code I am trying to fetch “the” expression from a multi dimensional array of strings.The result should count a number of expression occurrence and shows on the screen which is, in this case, is ‘4’.I am a noob so please stay easy on me. Thanks in advance