简体   繁体   中英

Remove duplicates from two separate arrays javascript

I am working on the roleUpdate event on my Discord bot, I have old role permissions, and new role permissions in the form of an array which prints:

[ 'VIEW_AUDIT_LOG', 'MANAGE_ROLES' ] // Old Roles
[ 'MANAGE_GUILD', 'VIEW_AUDIT_LOG', 'MANAGE_ROLES' ] // New Roles

Following this example, the output I need would be MANAGE_GUILD as that is the only changed object. How would I go about doing something like this?

Use this code

newroles.filter((role) => !oldroles.includes(role));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM