lodash 移除数据元素 pull without 删除数组元素
_.pull(array, [values])
移除所有经过 SameValueZero
等值比较为 true 的元素 .
without 不会修改原数组
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>移除数组元素</title> </head> <body> <script src="https://cdn.bootcss.com/lodash.js/4.17.10/lodash.min.js"></script> <script type="text/javascript"> var arr1 = [1, 2, 3, 1, 2, 3]; var arr2= _.without(arr1, 2, 3); console.log(arr1); //[1, 2, 3, 1, 2, 3] console.log(arr2); //[1, 1] var arr3 = _.pull(arr1, 2, 3); console.log(arr1); //[1, 1] console.log(arr3); //[1, 1] </script> </body> </html>
作者:孟繁贵 Email:meng010387@126.com 期待共同进步!