Currently, I am facing a challenge in my angularjs application. I have a huge array containing the cast of a movie, which includes directors, producers, and film crew members. My goal is to create a new array specifically for the director(s).
I am unsure about how to filter and extract specific objects from one array to form a new array. To illustrate, consider this brief example:
this.products = [
{name: "apple", category: "fruit"},
{name: "iPhone", category: "tech"},
{name: "banana", category: "fruit"}
];
this.fruits = [];
for(i = 0; i < products.length; i++) {
if (products.category[i] == "fruit") {
/*code to add object to fruits array*/
}
}
I would greatly appreciate any assistance on how to achieve this task! Thank you!