Skip to content
大纲

根据元素值移除数组的元素

语法

js
import { arrRemoveEle } from 'warbler-js';
const result = arrRemoveEle(arr, el);

参数

  • arr (Array) : 需要删除元素的数组。
  • el (Number | String) : 将要删除的元素。

返回值

Array : 删除元素后的数组。

源码

js
const arrRemoveEle = (arr, el) => arr.filter((i) => i !== el);

例子

js
import { arrRemoveEle } from 'warbler-js';
const ages = [1, 2, 3, 4, 5, 6, 7, 8];
const names = ['张三', '李四', '王二麻子', '一尾流莺'];
const result1 = arrRemoveEle(ages, 3);
const result2 = arrRemoveEle(names, '一尾流莺');
console.log(result1); //=> [1,2,4,5,6,7,8]
console.log(result2); //=> ['张三', '李四', '王二麻子']

添加版本

1.2.0

Released under the MIT License.