Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to break out of a typescript map

I have an array props.values and an item rendering function props.renderPreview.

So far I rendered all of the items on the list using props.value.map(props.renderPreview)

Now I wish to have the option to render only the first n items, passed in using props.maxItemsInPreview. Is there way to add max items to the map, having it stop at the n+1 iteration?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Consider using Array.protottype.slice:

props.value.slice(0,2).map(props.renderPreview)

The slice() method returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading