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?

1
  • Why would that not work if value was an object? It just needs to be inArray. Commented Aug 18, 2013 at 10:50

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.