Limit items in a .map loop

You could use Array#slice and take only the elements you need.

var film = this.props.data.slice(0, 5).map((item) => {
        return <FilmItem key={item.id} film={item} />
    });

return film;

If you do not need the original array anymore, you could mutate the array by setting the length to 5 and iterate them.

Leave a Comment