Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  5] [ 1]  / answers: 1 / hits: 38397  / 8 Years ago, fri, november 18, 2016, 12:00:00

I want to skip the first in the .map function what I do now is this:



block.gallery.map((item, i) => (
<div className=gallery-item key={i}>
{ block.gallery.length > 4 && i !== 0 ?
<div className=inner>
<img src={block.gallery[i].images.thumbnail_sm} alt={block.title} srcSet={`${block.gallery[i].images.thumbnail_md} 1x, ${block.gallery[i].images.thumbnail_lg} 2x`} className=img-fluid title= />
<div className=img-overlay>
<span className=img-overlay-body>{ block.gallery.length - 4 }+ <span className=hidden-xs>Foto's</span></span>
</div>
</div>
:
<img src=http://placehold.it/800x538 alt= className=img-fluid title= />
}

More From » reactjs

 Answers
32

So slice it to skip the first



block.gallery.slice(1).map(...)


You also need to reference the item passed into map, not using the index with the orginal array.



block.gallery[i].images.thumbnail_sm


should be



item.images.thumbnail_sm

[#60008] Wednesday, November 16, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zahrafrancisr

Total Points: 176
Total Questions: 105
Total Answers: 99

Location: Svalbard and Jan Mayen
Member since Sun, Sep 25, 2022
2 Years ago
;