I am looking to eliminate users from the removeUser
array based on their userName
values using lodash. Here is the data I have:
{"users":[
{"title":"Mr", "firstName":"John", "lastName":"Doe", "email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e9838d868ca98e86868e858cc78a8684">[email protected]</a>", "userName" : "jdoe", "groups": [{"name": "Manager"}]},
{"title":"Ms", "firstName":"Anna", "lastName":"Smith","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3c5d4f515548547c5b53535b5059125f5351">[email protected]</a>", "userName" : "asmith", "groups": [{"name": "Administrator"}, {"name": "Manager"}]},
{"title":"Mr", "firstName":"Peter", "lastName":"Jones", "email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0d7d676263687e4d6a62626a6168236e6260">[email protected]</a>", "userName" : "pjones", "groups": [{"name": "Administrator"}, {"name": "Manager"}]},
{"title":"Ms", "firstName":"Jenny", "lastName":"Otter","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c9a3a6bdbdacbb89aea6a6aea5ace7aaa6a4">[email protected]</a>", "userName" : "jotter", "groups": [{"name": "Administrator"}, {"name": "Manager"}]}
]}
var removeUser = ['jdoe', 'asmith']; //usernames of users to be removed
This is my current code snippet but it requires a foreach loop:
_remove(users, { userName: [removeUser]})
I would like to use the foreach loop to update the users
array as follows:
{"users":[
{"title":"Mr", "firstName":"Peter", "lastName":"Jones", "email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a2d2c8cdccc7d1e2c5cdcdc5cec78cc1cdcf">[email protected]</a>", "userName" : "pjones", "groups": [{"name": "Administrator"}, {"name": "Manager"}]},
{"title":"Ms", "firstName":"Jenny", "lastName":"Otter","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7a10150e0e1f083a1d15151d161f54191517">[email protected]</a>", "userName" : "jotter", "groups": [{"name": "Administrator"}, {"name": "Manager"}]}
]}