Home:ALL Converter>How do I filter table with value that matches value in another array?

How do I filter table with value that matches value in another array?

Ask Time:2022-11-24T19:16:58         Author:Jukka Koivu

Json Formatter

What way should I filter this table so returns table with rows only that matches the customAttribute value that comes from amplify auth and is set to state. This is will result of getting value: 'valke' and let's say there is 2 entries in table that has same value valke it would only show those in the table.

useEffect(() => {
  Auth.currentUserInfo()
    .then((res) => {
      console.log("res: ", res);
      setCustomer(res.attributes["custom:customer"]);
    })
    .catch((err) => {
      console.error(err);
    });
}, []);

Here I'm mapping the table. The value I want to compare to is the customer_name value that comes from another array. If customer === customer_name then show only those rows in the table. const customer_name is there because the projects array has them as id

{
  dataFiltered
    .filter((customer) => customers.map((c) => c[1] === customer))
    .map((project) => {
      const customer_name = customers.map((c) => {
        return c[0] === project[2] ? c[1] : null;
      });
      return (
        <TableRow key={project[0]} hover={true}>
        ...
      )
    });
}

Author:Jukka Koivu,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/74559898/how-do-i-filter-table-with-value-that-matches-value-in-another-array
yy