_.dropRightWhile(array, [predicate=_.identity])
创建一个切片数组,去除array
中从 predicate
返回假值开始到尾部的部分。predicate 会传入3个参数: (value, index, array)。
<template>
<div>
<h3>
创建一个切片数组,去除array中从 predicate
返回假值开始到尾部的部分。predicate 会传入3个参数: (value, index,
array)。
</h3>
</div>
</template>
<script>
import _ from "lodash"; // 引入
export default {
data() {
return {};
},
mounted() {
// _.dropRightWhile(array, [predicate=_.identity])
// 创建一个切片数组,去除array中从 predicate 返回假值开始到尾部的部分。predicate 会传入3个参数: (value, index, array)。
var users = [
{ user: "barney", active: true },
{ user: "fred", active: false },
{ user: "pebbles", active: false },
];
_.dropRightWhile(users, function (o) {
return !o.active;
});
// => objects for ['barney']
// The `_.matches` iteratee shorthand.
_.dropRightWhile(users, { user: "pebbles", active: false });
// => objects for ['barney', 'fred']
// The `_.matchesProperty` iteratee shorthand.
_.dropRightWhile(users, ["active", false]);
// => objects for ['barney']
// The `_.property` iteratee shorthand.
_.dropRightWhile(users, "active");
// => objects for ['barney', 'fred', 'pebbles']
},
methods: {},
};
</script>