0

So I need to perform two actions 1) filter my array and 2) update the unfiltered values. currently, I am doing it this way and it works fine.

let installData = state.installData.filter((item) => {
        return item.sensor !== action.data.sensor;
      });

      installData = installData.map((item) => {
        return { ...item, asOfDate: false };
      });

however, I am doing operations here and was wondering if there is a more efficient way to update the value of my item directly inside the filtred method without having to use map

1
  • 2
    Your operations seem fine, though you could chain them to avoid reassigning installData. const installData = state.installData.filter((item) => ...).map((item) => ...); Commented May 17, 2022 at 21:09

1 Answer 1

1

I believe you could just use reduce and combine operations into a single function

 let installData = state.installData.reduce((acc,item) => {
     if (item.sensor !== action.data.sensor) acc.push({...item, asOfDate: false});
     return acc;
  },[]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.