drop()、dropRight()、dropWhile()、dropRightWhile()
drop()、dropRight()、dropWhile()、dropRightWhile()方法也是用来截取数组中的元素,其内部都是基于slice方法实现的。_.drop(array, n)
是从索引值n
开始截取到array.length
为止;_.dropRight(array, n)
就是从索引0
开始且截取到索引为array.length - n
为止;
example:
_.drop([{
a:1}, 2, ['b', 'c'], 3 ,5], 2)
// [['b', 'c'], 3 ,5]
_.dropRight([{
a:1}, 2, ['b', 'c'], 3 ,5], 2)
// [{a:1}, 2, ['b', 'c']]
function less4(a) {
return a < 4
}
_.dropWhile([3, 2, 5, 1, 4