如何使用lodash的takeRightWhile和起始索引从数组中获取值?lodash takeRight从起始索引
这里的重点是我想从一个特定的起点向后迭代,直到某个参数被满足。什么我想要做
例子:
const myArray = [
{val: 'a', condition: true},
{val: 'b', condition: false},
{val: 'c', condition: true},
{val: 'd', condition: true},
{val: 'e', condition: true},
{val: 'f', condition: true},
{val: 'g', condition: false},
];
const startAt = 5;
const myValues = _.takeRightWhile(myArray, startAt, {return condition === true});
// --> [{val: 'c', condition: true}, {val: 'd', condition: true}, {val: 'e', condition: true}]
我看过的文档https://lodash.com/docs/4.17.4#takeRightWhile并不能真正告诉我们,如果这是可能的。
有没有更好的方法来做到这一点?
谢谢!这个解决方案还包括了我的包含当前(startsAt)值的问题。 – Winter