I would like to filter the items from an array based on a string and save them to a new array to then perform some other functions on that second array. How would I best achieve this?
Here is what I have so far.
for (var i = 0; i < array.length; i++) {
var num = i;
var item = array.entries[i];
var str = item.content;
var newArray = new Array();
if (str.indexOf("filter") !== -1) {
// If the content of the item contains a given string then ad it to the array.
newArray.push(item);
if (num === array.length) {
// When we reach the end of the first array, perform something on the new array.
doSomeFunction();
}
}
function doSomeFunction() {
// Now do something with the new array
for (var j = 0; j < newArray.length; j++) {
// Blah, blah, blah...
}
}
}
Thanks for any help.