Javascript 映射数组最后一项 [英] Javascript Map Array Last Item
本文介绍了Javascript 映射数组最后一项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个:
map = ranks.map((row, r) => (
row.map((rank, i) => {
return [element(r, i, state, rank, toggled, onClick)];
})
));
它映射到一个二维数组.在每一行之后,我想插入 <div class="clearfix"></div>
.
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?
推荐答案
const rowLen = row.length;
row.map((rank, i) => {
if (rowLen === i + 1) {
// last one
} else {
// not last one
}
})
这篇关于Javascript 映射数组最后一项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文