javascript - 如何根据数组中的最后一个索引隐藏元素?
问题描述
所以我有一个对象数组,我们称之为questions
{questions.length !== lastIndexOfTheQuestionsArray && (
<ElementToShowIfItIsNotTheLastIndexOfTheQuestionsArray />
)}
所以这基本上就是我所需要的;ElementToShowIfItIsNotTheLastIndexOfTheQuestionsArray
当元素到达questions
数组的最后一个索引时隐藏元素。
解决方案
您可以slice
在调用之前删除数组的最后一个元素map
。
array.slice(0, -1).map(/* ... */)
推荐阅读
- excel - Excel 公式从格式奇怪的列表中获取额外数据
- awesome-wm - 配置上下文相关菜单
- git - Git 交互式变基,在 git blame 中保留作者
- c++ - C++静态模板类成员作为友元模板函数默认参数
- python - 是否有可以将 NumPy 的广播规则应用于形状列表并返回最终形状的函数?
- asp.net - Crystal Reports 的问题无法反映 SQL DB 的更改
- javascript - 减少 react-native-paper TextInput 的高度和垂直填充
- android - 我在 Play 商店中启动应用程序后,片段工具栏后退按钮未显示
- swift - 转换一个函数来处理 Double 和 Float... 使用 FloatingPoint 类型?
- php - 视图全局 PHP 过滤器在重写字段时无法正常工作