I need a function to filter my array and return results based on user inputs.
var Myarray= [
{Date:"1-Jan-2020",Name:"A", Id: 1},
{Date:"1-Feb-2020",Name:"B", Id: 2},
{Date:"1-Mar-2020",Name:"C", Id: 3}
...
]
The filter needs to be dynamic. User MUST input at least Date or Name or both together. ID is optional
Is there a smart way to build the filter expression in the function based what ever inputs the user inputs?
More info: I have a UI. The user will have search parameters to choose from for returning date. Date, Name and ID. The user MUST choose at least The Date or Name. The ID is optional but must be considered in the function that will accept the parameters sent. After the users inputs the values, they are passed to a JS function that should filter an array that holds the data. After the filters are applied to the array, a new array is filled with the filtered data. Ex.user sends Date without name or or ID, Then array only filters based on date. Ex2. user sends Name without date or id, then array only filters based on name. Ex3. user sends date and name without id, then array filters based on date and name. Ex4. user sends Date and id without name, then array filters based on date and id. Ex5. user sends name and id without date, then array filters by name and id. ex6 user sends date and name and id, then array filters based on date and name and id. Ex7 user sends id, funtction will NOT allow id to sent alone without either date or name