What should i do to stop rendering all the items from array in map() and limit to a required number (let's say 4)?
1 Answer
you can use slice method to limit the number of elements to n in the map:
let renderedData = this.state.elements.slice(0,n).map((element)=>{
return (<div key={element.id}>{element.txt}</div>)
}
if you want to map only 4 then use 4 in place of n