且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

找到匹配项后删除数组中所有元素的Lodash方法?

更新时间:2023-02-18 08:52:37

这可以使用Array对象的indexOf和splice函数来实现.以下是同时使用Lodash和javascript函数的实现

This can be achieved using indexOf and splice functions of an Array object. Below are the implementation using both Lodash and javascript functions

blogArray.splice(0,blogArray.indexOf(matchingEl))

_.slice(blogArray, 0, _.findIndex(blogArray, function(k){return k == matchingEl;})