IndexOfResultDiv
by wllai2001
HTML
<div id="IndexOfResult"></div>
JavaScript
// 假設的字串陣列
const data = ['Hello world',
'Lorem ipsum dolor sit amet',
'Consectetur adipiscing elit',
'there Hello'];
const IndexOfResultDiv = document.getElementById('IndexOfResult');
// 搜尋特定文字的函式
function IndexOfSearch() {
let results = "";
data.forEach(function(item){
if(item.indexOf("Hello") >= 0){
results += item +'<br/>';
}
});
IndexOfResultDiv.innerHTML = results;
}
IndexOfSearch();