I have created an array containing some tags:
var myArray = [
"mouse",
"common",
"malcom",
"mountain",
"melon",
"table"
];
Now, I need to extract these defined tags from a given string. For instance,
from the string: the mouse is on the desk
, I want to extract the "mouse" tag
or from the string the mouse is on the table
, I aim to extract both "mouse" and "table" tags.
The code I've implemented serves this purpose partially, but there seems to be an issue:
var myArray = [
"mouse",
"common",
"malcom",
"mountain",
"melon",
"table"
];
Object.defineProperty(Array.prototype, "MatchInArray", {
enumerable: false,
value: function(value) {
return this.filter(function(currentItem) {
return currentItem.match(value);
});
}
});
function doSearch(text){
out = myArray.filter(function(currentItem){
return currentItem.toLowerCase().indexOf(text) !== -1;
});
return out;
}
myInput.oninput = function(){
var XXX = this.value;
var YYY = XXX.replace(/ /g,',');
var ZZZ = YYY.split(',');
for(var i=0; i<ZZZ.length; i++){
output.innerHTML = doSearch(ZZZ[i]);
}
//output.innerHTML = doSearch(this.value);
};
What am I doing wrong?