I have an Array of strings as:
todo=[
'Get up',
'Brush my teeth',
'Go to work',
'play Games'
];
I am trying to match it with this:
Template:
<input (input)="checkArrays($event)" />
while in my Component.ts the function I am using for it is :
checkArrays(e){
let query=e.target.value;
console.log(query);
let todoResult = this.todo.findIndex((item) => { return item.startsWith(query);})
let doneResult = this.done.findIndex((item) => { return item.startsWith(query);})
if(doneResult!=-1){
console.log('found in Tasks (done)'+doneResult)
}if(todoResult!=-1){
console.log('found in Tasks (todo)'+todoResult)
}
what this does is that when i start typing 'G' it matches the very first item in the array which is 'Get up' and do not match with 'Go to work'. It matches with 'Go to work' when i type 'Go'. The functionality I want is basically it should give me both the 'Get up' and 'Go to work' when I start typing 'G'. some sort of the sub-string like functionality.
Aucun commentaire:
Enregistrer un commentaire