最新消息:20210917 已从crifan.com换到crifan.org

【已解决】js中如何删除列表中元素

JS crifan 749浏览 0评论
写小程序期间:
【已解决】小程序中实现列表中第一个元素特殊显示
需要从list中删除某个需要高亮显示的元素。
所以就是js中从list删除item
js list remove item
How do I remove a particular element from an array in JavaScript? – Stack Overflow
JavaScript: Remove Element from an Array – HostingAdvice.com
https://www.hostingadvice.com/how-to/javascript-remove-element-array/
【总结】
最后整理成:
const removeListItem = (originList, itemInList) => {
  console.log("removeListItem: originList=%o, itemInList=%o", originList, itemInList)
  var foundIndex = originList.indexOf(itemInList)
  console.log("foundIndex=%s", foundIndex)
  if (foundIndex >= 0){
    originList.splice(foundIndex, 1)
  }
  console.log("originList=%s", originList)
  return originList
}
用法:
normalTagList = util.removeListItem(newTagList, this.properties.highlightTag)
highlightTagList = [this.properties.highlightTag]
效果:

转载请注明:在路上 » 【已解决】js中如何删除列表中元素

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
92 queries in 0.173 seconds, using 23.33MB memory