Link to home
Start Free TrialLog in
Avatar of justaphase
justaphaseFlag for Portugal

asked on

json array, remove all elements contained in another json array

Hello Experts,

I've seen several examples on the web filtering arrays, using for example jQuery grep.
But all i see i a little more simple than what i want.

Maybe this is more simple that i think..

I have this two arrays:
var searchtag_catg       = [{ id: 2, tb: 'text2', search: 'test2'},{ id: 4, tb: 'text4', search: 'test4'}];

var categories       = [{ id: 1, tb: 'text1', search: 'test1'},{ id: 2, tb: 'text2', search: 'test2'},{ id: 3, tb: 'text3', search: 'test3'},{ id: 4, tb: 'text4', search: 'test4'}];

Open in new window

And i want to show the records in the array categories that are not in searchtag_catg array, using the id key...
How can i do this?

Thx in advanced :)
Miguel
ASKER CERTIFIED SOLUTION
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of justaphase

ASKER

Sorry i didn't answer sooner!

Steve, amazing!

Worked like a charm.

Thx :)

Miguel