cocacrave cocacrave - 4 months ago 13
Javascript Question

Javascript Map Array Last Item

I have this:

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


It maps through a 2d array.
After each row, I'd like to insert .

I think if I could somehow get the last index in each row I can put it in row map. Can somehow show me how?

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