【问题标题】:How to hide an element based on the last index in an array?如何根据数组中的最后一个索引隐藏元素?
【发布时间】:2021-10-05 13:20:28
【问题描述】:

所以我有一个对象数组,我们称之为questions

{questions.length !== lastIndexOfTheQuestionsArray && (
  <ElementToShowIfItIsNotTheLastIndexOfTheQuestionsArray />
)}

所以这基本上就是我所需要的;在到达questions 数组的最后一个索引时隐藏ElementToShowIfItIsNotTheLastIndexOfTheQuestionsArray 元素。

【问题讨论】:

标签: javascript arrays reactjs ecmascript-6


【解决方案1】:

您可以在调用map 之前将slice 删除数组中的最后一个元素。

array.slice(0, -1).map(/* ... */)

【讨论】:

    猜你喜欢
    • 2023-02-14
    • 2022-11-18
    • 1970-01-01
    • 2022-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多