//Using the new ES6 Syntax console.log(["a", "b", "c", "d", "e", "f", "g"].filter(el => !["b", "c", "g"].includes(el))); // OR // Main array let myArray = ["a", "b", "c", "d", "e", "f", "g"]; // Array to remove const toRemove = ["b", "c", "g"]; const diff = () => (myArray = myArray.filter((el) => !toRemove.includes(el))); console.log(diff()); // [ 'a', 'd', 'e', 'f' ] // OR const diff2 = () => { return myArray = myArray.filter((el) => !toRemove.includes(el)); }; console.log(diff2()); // [ 'a', 'd', 'e', 'f' ]
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter