0

I am looking for a solution for the following problem. I am working with an object that looks:

0: {userId: 139, moveId: 169, moveName: "FirstRoadMove", building: {…}}
1: {userId: 139, moveId: 171, moveName: "FirstRoadMove", building: {…}}
2: {userId: 139, moveId: 173, moveName: "FirstRoadMove", building: {…}}
3: {userId: 139, moveId: 175, moveName: "FirstRoadMove", building: {…}}
4: {userId: 139, moveId: 177, moveName: "FirstRoadMove", building: {…}}
5: {userId: 139, moveId: 179, moveName: "FirstRoadMove", building: {…}}

And I also have a component:

    <button className={`actionBoxButton ${props.moves[0].moveName !== "FirstSettlementMove"  ? "actionBoxButtonGrey" : ''}`}

What I am trying to achieve is to not only check for the button if the first elements of moves has a key with value FirstSettlementMove e.g. but every element of the object. So in semi pseudo something like:

    <button className={`actionBoxButton ${props.moves[first to last].moveName !== "FirstSettlementMove"  ? "actionBoxButtonGrey" : ''}`}

Thank you in advance!

2
  • you want that on one button or more buttons based on that ? and what do you want to acheive if say on of the moveName is something other than "FirstSettelmentMove" Commented May 3, 2020 at 22:09
  • Now it maybe does make more sense, so I want to check if in the moves object, there is an moveName with vale "FirstSettlementMove" and if not do "actionBoxButtonGrey" : '' Commented May 3, 2020 at 22:15

1 Answer 1

2

You could change your way of thinking. Instead of trying to check all sub object with moveName = firstSettleMentMove, you could check if there is a sub object without this value by doing as follow:

props.move.filter(x => x.moveName !== 'FirstSettlementMove').length > 0

If props.move isn't an array, you can still use Array.from(props.move) to convert it.

Also, if your object has indexes as you showed us, you can 'remove' it with Object.values(props.move).

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.