我收到一个有很多键的对象,其中两个是“title”和“body”,我还有一个包含一些关键字的数组。我需要在 object.body 中匹配这些数组关键字以以某种方式突出显示它们,一种选择可能是将这些匹配的单词包装在<pre class="highlight"> Matched word inside Object.body </pre>
标签中。
我宁愿使用原始 JavaScript 来实现这一点。
我试过了:
function (data) {
// parseKeys() returns an array with the words to find inside object.body
var key_words = this.parseKeys();
// data is the object within I have to find inside key:body the array strings
for (var i = 0; i < data.length; i++) {
if (data[i].body.includes(key)){
console.log("****");
}
}
}