0

Notice in the code sample below that I'm mapping all the data into ResultItems

    {store.results.data.map( result =>
                                <ResultItem key={result.id}
                                title={result.title}
                                description={result.description}
                                start_date={result.start_date}
                                end_date={result.end_date}
                                vendor_name={result.vendor.name}
                                buyer_name={result.buyer.name}
                                preview_file={result.preview_file}
                                status={result.status}
                                />)}

what I want to do is keep count of how many resultitems there are and display that number in the DOM

Any ideas on how to do that?

4
  • 2
    Uh... store.results.data.length? Commented Feb 16, 2018 at 9:59
  • that worked! thanks so much! Commented Feb 16, 2018 at 10:01
  • such a simple solution! it's late over here, I'm not thinking...too bad I can't vote this as best answer Commented Feb 16, 2018 at 10:01
  • Possible duplicate of NodeJS Count how many objects in array? Commented Feb 16, 2018 at 10:05

1 Answer 1

0

Use the length of the array to know how many items the array has or if you want to access each one just use the index of the map function.

    const length = store.results.data.length

    {store.results.data.map( (result, index) =>
           <ResultItem
               position={index}
               (...)
           />
    )}
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.