Something I'm trying to do in an angularjs app that I'm making. I have a large array of the cast of a movie including directors, producers, film crew etc. and I want to make a new array of just the director(s).
I don't know how to fill a new array with specific objects form another array. Here's a quick simple example of what I mean:
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*/
}
}
Please help! Thank you!