Wie bekomme ich die Werte von einem Array mit lodash TakeRightWhile mit einem Startindex?lodash TakeRightWhile vom Startindex
Der Punkt hier ist, dass ich von einem bestimmten Startpunkt rückwärts iterieren will, bis ein bestimmtes Argument erfüllt ist.
Beispiel von dem, was ich tun möchte:
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}]
Ich habe in der Dokumentation https://lodash.com/docs/4.17.4#takeRightWhile geschaut und kann nicht wirklich sagen, ob dies möglich ist.
Gibt es vielleicht einen besseren Weg, dies zu tun?
Danke! Diese Lösung beinhaltete mein Problem, den aktuellen Wert (startsAt) mit einzubeziehen. – Winter