标签: string counting
如何计算一个变量的值在另一个变量中出现的频率,并将该数字存储在第三个变量中。
var theKeyword = "apple"; var theText = "This is an apple and this is an apple, but this is a banana." var theNumber = (theText.match(/theKeyword/g) || []).length; console.log(theNumber);
不幸的是,这行不通。