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?
>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.