jQuery Remove object from array

Hello I have an array of objects where each object contains: name, url.

I need to remove an object from the array where the name and url match. How is that accomplished?
Scott BaldridgeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rainer JeschorCommented:
Hi,

this should do the trick:
    var testArray = [{
        name: "Microsoft",
        url: "www.microsoft.com"
    }, {
        name: "AA",
        url: "AA"
    }, {
        name: "AAA",
        url: "ABA"
    }, {
        name: "Apple",
        url: "www.apple.com"
    }];
    var cleanedArray = $.grep(testArray, function (item, index) {
        return (item.name != item.url);
    });

Open in new window


Alternative:
Just overwrite the Array variable (instead of generating a new one).

Live sample:
http://jsfiddle.net/EE_RainerJ/0xh1pxdp/

HTH
Rainer

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scott BaldridgeAuthor Commented:
Thanks for helping!

I'm removing the item from the table selector with the code below which works fine, but I also need to remove the item from my collection, _LinkStorage which I persist to the database.

How can I use the code you provided to remove the item from my collection?

var cleanedArray = $.grep(testArray, function (item, index) {
        return (item.name != item.url);


$(document).on('click', '.deleteLink', function (e) {
               
                var tr = $(this).closest('tr');
                var name = tr.find('.link').text();
                var url = tr.find('.link').attr('href');

                var removeItem = $(this);
                removeItem.closest("tr").remove();
             });
Rainer JeschorCommented:
Hi.
sorry but with your last post I got lost.

Your initial question was to remove an item from an array of objects where two named values are identical.

Now you ask something completely different, using jQuery objects.

If the above script does what it should, could you please close this question and open a new one with more details for your current issue?
Please provide also the HTML source or a link to your page (or try to repro on jsFiddle).

Thanks
Rainer
Scott BaldridgeAuthor Commented:
Thank you for your assistance.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.