filter map objects using javascript #621
-
I have a map object with key value pair as shown below
I have a search input where i enter the string. Based on this string value, i want to filter this above map object. Suppose user enters "50". So i need to check for properties So in this case, user enters 50, i am expecting the below result because those get matched with Expected output-
In order to achieve this way of filtering, i am doing the following but i dont get the expected filter results. Can someone let me know where i am going wrong with this.
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
@NitishKumar525 Your filtering function looks mostly correct, but there're some issues.
Here's updated code. const searchException = () => { return new Map( Array.from(input).filter(([key, value]) => { const matchInvocations = value.invocations.some((invocation) => invocation?.radar?.includes(filterFailureInput) ); const matchErrorSummary =
value?.testErrorSummary?.toLowerCase().includes(filterFailureInput.toLowerCase()) ||
value?.appErrorSummaryKeyword?.toLowerCase()?.includes(filterFailureInput.toLowerCase());
return matchInvocations || matchErrorSummary;
}) ); }; |
Beta Was this translation helpful? Give feedback.
-
thank you @mdazfar2 - understood what i was doing wrong. thanks for explanation. can you confirm if your final code is properly formatted in the answer. |
Beta Was this translation helpful? Give feedback.
@NitishKumar525 Your filtering function looks mostly correct, but there're some issues.
Here's updated code.
const searchException = () => { return new Map( Array.from(input).filter(([key, value]) => { const matchInvocations = value.invocations.some((invocation) => invocation?.radar?.includes(filterFailureInput) );
); };