-4

I have this array

 {product.images.map((img, index) => (
                        <img key={index} src={img.url}
                        
                         />
                    ))}

as I only wanna render first 5 photos.. How to get the first 5 photos from an array ??

Rafal
  • 63
  • 2
  • 9
  • 3
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice – Andreas Mar 01 '21 at 15:31
  • 5
    Really, you could google this and get your answer in 5 seconds. There's no point creating a Stackoverflow question for this – Jeremy Thille Mar 01 '21 at 15:33

1 Answers1

2
{ product.images.slice(0, 5).map((img, index) => (
    <img key={index} src={img.url}/>
)) }
Josh Merlino
  • 622
  • 6
  • 10