Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
188
rated 0 times [  193] [ 5]  / answers: 1 / hits: 167989  / 8 Years ago, mon, july 4, 2016, 12:00:00

I have this:



map = ranks.map((row, r) => (
row.map((rank, i) => {
return [element(r, i, state, rank, toggled, onClick)];
})
));


It maps through a 2-dimentional array.
After each row, I'd like to insert <div class=clearfix></div>.



I think, if I could somehow get the last index for each row, so I will be able to use it in the row map callback. Can someone show me how to do it?


More From » arrays

 Answers
4

Try something like:


row.map((rank, i, row) => {
if (i + 1 === row.length) {
// Last one.
} else {
// Not last one.
}
})

Old answer:


const rowLen = row.length;
row.map((rank, i) => {
if (rowLen === i + 1) {
// last one
} else {
// not last one
}
})

[#61527] Friday, July 1, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jennifer

Total Points: 517
Total Questions: 110
Total Answers: 104

Location: New Caledonia
Member since Fri, Sep 11, 2020
4 Years ago
;