In the provided array below: https://i.sstatic.net/HtmTI.png
My objective is to create a new array that starts with the element in the initial array where its name property is 'Raged Barbarian'. I have a solution for this, but I believe there may be a more semantically appropriate approach.
Here is my current method:
public getNewArr(initialArr) {
const newArr = [];
let isRagedBarbarian: boolean = false;
for (const troop of initialArr) {
if (troop.name === 'Raged Barbarian') {
isRagedBarbarian = true;
}
if (isRagedBarbarian === true) {
newArr.push(troop);
}
}