2

I currently have a function that successfully removes an item from an array but only for a simple collection. I am trying to extend this so it also works for removing object from an array but stumped. Can anyone help? Here is what I got so far:

remove: function (arr, value) {
    if (_.isObject(value)) {
       //HOW TO HANDLE THIS, MAYBE USE THIS FOR HELP? _.where(arr, value)
    } else {
        //THIS WORKS!
        if ($.inArray(value, arr) >= 0)
            arr.splice($.inArray(value, arr), 1);
    }
}

For the first if-statement, I am having trouble finding the index of the object. Using underscore.js I can find the object itself, but don;t know how to find the index so I can remove it from there. Any ideas to solve this or a better way?

TruMan1
  • 33,665
  • 59
  • 184
  • 335

0 Answers0