Made a search function which takes in an object (e) and filter value (filter) gives a 1 or 0/ true or false, which is then passed to a filter method, which will return the needed (search) object.
The search function accepts an object and a filter variable as a parameter, it then makes an array of the values from the key value pair using the Object.values() method. The array is then destuctured and only needed elements are taken out, which are then used to make a new array.
Method array.prototype.some() ( written as [whatever array u have].some( (element) => { return //condition } )) is used which runs through each element of array to test the given condition.
Here the condition is element?.toLowerCase().includes(filter.toLowerCase() here ?. is a nullish coalescing operator this returns a 0 if element is nullish (like undefined, "", null), or applies the subsequent methods if not.
The condition takes in a string element, converts it to lowercase and checks if it has the filter value (converted to lower case in it), then returns 0 for not included and 1 for included.
Finally we use the function as data.past.filter((e)=>search(e,filter)), data.past is an array of objects, thus .filter() method sends in each element which is in turn an object as (e) into the search function. The search function then returns 0 or 1 based on object received and then .filter() returns the object if search() search returned 1.
Object.values()
method. The array is then destuctured and only needed elements are taken out, which are then used to make a new array.array.prototype.some()
( written as[whatever array u have].some( (element) => { return //condition } )
) is used which runs through each element of array to test the given condition.element?.toLowerCase().includes(filter.toLowerCase()
here?.
is a nullish coalescing operator this returns a 0 if element is nullish (like undefined, "", null), or applies the subsequent methods if not.element
, converts it to lowercase and checks if it has the filter value (converted to lower case in it), then returns 0 for not included and 1 for included.data.past.filter((e)=>search(e,filter))
, data.past is an array of objects, thus .filter() method sends in each element which is in turn an object as (e) into the search function. The search function then returns 0 or 1 based on object received and then.filter()
returns the object ifsearch()
search returned 1.