1

Lets say I retrieve data from my local api, using this snippet

{console.log("Bin", this.state.rows.filter(qc => qc.BinsByDayByOrchardsQCs.length > 0).map((bin) => bin))}

I retrieve a result that looks something like this

    0: {…}
    1: {…}
    2: {…}

As a place holder, this is what I have

<div className="column-label qc-number">{this.state.rows.filter(bin => bin.BinsByDayByOrchardsQCs.length > 0).length}</div>

If I wanted to display each index value of that map, how would I be able to do that?

1 Answer 1

2
{console.log("Bin", this.state.rows.filter(qc => qc.BinsByDayByOrchardsQCs.length > 0).map((bin, i) => i))}

Second argument in map method is the index. If you want to give them both back I suggest an array [bin, i] or object {bin: bin, index: i}

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

1 Comment

or map((bin, index) => { ...bin, index }) to maintain all properties and add index as a property

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.