I am trying to implement a search feature on an existing array but I am getting an error stating that 'filter is not a function'. Maybe I am not passing in the correct parameters?
searchValue = '';
stringResult = [];
fields = ['Name'];
this.stringResult = this.sectionInvLineItems;
this.arrayFields = this.fields;
this.searchVal = this.searchValue;
console.log( 'stringResult 2 ' + this.stringResult ); // [object Object]
console.log( 'arrayFields 2 ' + this.arrayFields ); //returns Name
console.log( 'searchVal 2 ' + this.searchVal ); //returns what is being typed
const filterData = (stringResult, arrayFields, searchVal) => {
return stringResult.filter( item => !item[arrayFields].toLowerCase().search(searchVal.toLowerCase()));
};
if( this.searchValue.length > 2 ) {
const remaining = filterData( this.stringResult, this.arrayFields, this.searchValue );
this.stringResult = [ ...remaining ];
}
else {
this.displayedItems = [ ...this.stringResult ];
}