Question:I am fetching an array from my database , I am trying to map it in carousel, each slide must have 2 elements ,the next slide is 2 elements as well and so forth. I will explain this in the codes . This is the JSON format of the array :
blog, for example in the first slide it will display the 2 first elements of the array successfully , in the second slide it will get only a single element and it will have the index of the first slide’s last element (1) . I need a way to fix this to display in every slide 2 elements from the array accordingly ! I hope you did understand this question.
Answer:I think you are trying to use
sliceto split the array
nodesinto pairs of two – but that’s not how
sliceworks. It will give you just one array which is a subset of
Look at this answer to see how to split an array into pairs of two elements each:
nodesarray and then iterate over the pairs:
If you have better answer, please add a comment about this, thank you!