0

I want to map array and get indexes in return (currentValue is not needed). I want to avoid using unused arguments, so is there better way to do this:

 array.map((el, index) => { // el is not used anywhere
          return (
          <div>X</div>
          );
        })
3
  • 3
    People often call the variable _ in that case. Commented Aug 22, 2021 at 18:50
  • 3
    You're not using index, either. Commented Aug 22, 2021 at 18:51
  • 1
    And you forgot the > at the end of </div Commented Aug 22, 2021 at 18:51

2 Answers 2

3

If your want to use Array.map you can use _ as your value, this way you telling other developers that you don't plan to use that value. like:

someArray.map((_, index) => { /* your code */ })

Or your can simply use for loop.

Sign up to request clarification or add additional context in comments.

1 Comment

That's fine answer
-1

You have both options

Array.map(element, index)

As well as

Array.map(element)

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.