Be the first user to complete this post

  • 0
Add to List

Remove the elements of one array from another using underscore or raw javascript

It so happened that I wanted to get all the elements of the first array that were not present in the second array. Below are examples of getting the difference between two arrays using raw javascript and lodash or underscore.

Using raw javascript

[wpgist id="67c7cbf6fabbc3a1c452" file="1_array_diff_js.js"]

Using underscore or lodash

If you are using lodash or underscore, you have a couple of alternatives. [wpgist id="67c7cbf6fabbc3a1c452" file="2_array_diff_lodash.js"]

Also Read:

  1. Writing multiline sql queries in javascript using knex
  2. How to set the timeout of a test in mocha