按条件从左往右移除数组中的元素

index.ts

import * as _ from 'lodash'

const list = [
  { name: 'a', gender: 1 },
  { name: 'b', gender: 0 },
  { name: 'c', gender: 1 },
  { name: 'd', gender: 0 },
  { name: 'e', gender: 0 },
]
const arr1 = _.dropWhile(list, ({ gender }) => gender) // object arr: ['b', 'c', 'd', 'e']
const arr2 = _.dropWhile(list, ({ gender }) => !gender) // object arr: ['a', 'b', 'c', 'd', 'e']
const arr3 = _.dropWhile(list, { name: 'a', gender: 1 }) // object arr: [b', 'c', 'd', 'e']
const arr4 = _.dropWhile(list, ['gender', 1]) // object arr: ['b', 'c', 'd', 'e']
const arr5 = _.dropWhile(list, 'gender') // object arr: ['b', 'c', 'd', 'e']

posted on 2021-09-09 10:21  aisowe  阅读(43)  评论(0编辑  收藏  举报

导航