comparing two arrays in javascript returning differences
JavaScript
let difference = arr1.filter(x => !arr2.includes(x));function arrayDiff (a1, a2) {
var a = [], diff = [];
for (var i = 0; i < a1.length; i++) {
a[a1[i]] = true;
}
for (var i = 0; i < a2.length; i++) {
if (a[a2[i]]) {
delete a[a2[i]];
} else {
a[a2[i]] = true;
}
}
for (var k in a) {
diff.push(k);
}
return diff;
}
//usage:
console.log(arrayDiff(['red', 'white','green'], [ 'red','white', 'blue']));//["green", "blue"]
Also in JavaScript:
- Title
- How to append to a file in Node?
- Category
- JavaScript
- Title
- how to manage a db connection in javascript
- Category
- JavaScript
- Title
- contains substring javascript
- Category
- JavaScript
- Title
- how to mass comment in p5
- Category
- JavaScript
- Title
- how to create response time router node js
- Category
- JavaScript
- Title
- javascript click button by id
- Category
- JavaScript
- Title
- is object js
- Category
- JavaScript
- Title
- how to use function in javascript
- Category
- JavaScript
- Title
- get value javascript
- Category
- JavaScript
- Title
- javascript access pushed element
- Category
- JavaScript
- Title
- import vue js
- Category
- JavaScript
- Title
- export default react
- Category
- JavaScript
- Title
- javascript array split chunk
- Category
- JavaScript
- Title
- javascript addeventlistener
- Category
- JavaScript
- Title
- generate thumbnail of pdf using pf js
- Category
- JavaScript
- Title
- discord.js how to go back a file
- Category
- JavaScript
- Title
- integer to array javascript
- Category
- JavaScript
- Title
- javascript ajax request
- Category
- JavaScript
- Title
- how to square a value in javascript
- Category
- JavaScript
- Title
- add element to array javascript
- Category
- JavaScript
- Title
- closure javascript
- Category
- JavaScript
- Title
- how to place text at custom position on canvas in javascript
- Category
- JavaScript
- Title
- adding pre tag javascript
- Category
- JavaScript
- Title
- if condition in class angular 8
- Category
- JavaScript
- Title
- express server replit
- Category
- JavaScript
- Title
- if object is array javascript
- Category
- JavaScript
- Title
- Find channel discord js
- Category
- JavaScript
- Title
- how to count click events javascript
- Category
- JavaScript
- Title
- http requests in vue 3
- Category
- JavaScript
- Title
- best react native animation library
- Category
- JavaScript
- Title
- get value from textbox in vanilla javascript
- Category
- JavaScript
- Title
- drupal 8 node has field
- Category
- JavaScript
- Title
- a simple javascript calculator
- Category
- JavaScript
- Title
- fixed header on scroll vuejs
- Category
- JavaScript
- Title
- is forEach sync js
- Category
- JavaScript
- Title
- append rotated triangle in anchor tag
- Category
- JavaScript
- Title
- addEventListener
- Category
- JavaScript
- Title
- electron jquery
- Category
- JavaScript
- Title
- font awesome in react
- Category
- JavaScript
- Title
- adding cors parameters to extjs ajax
- Category
- JavaScript
- Title
- how to know which button clicked in javascript
- Category
- JavaScript
- Title
- angular sumar labels
- Category
- JavaScript
- Title
- how to get last string in javascript
- Category
- JavaScript
- Title
- javascript array stackoverflow
- Category
- JavaScript
- Title
- do more than one thing at start of or loop javascript
- Category
- JavaScript
- Title
- angular observable subscribe and unsubscribe
- Category
- JavaScript
- Title
- angular cli skip-tests
- Category
- JavaScript
- Title
- how to convert time to am pm in javascript
- Category
- JavaScript
- Title
- disable autocomplete javascript
- Category
- JavaScript
- Title
- change p tag text javascript
- Category
- JavaScript
- Title
- bootstrap 4 hide modal via javascript
- Category
- JavaScript
- Title
- How to abreviate digits in js
- Category
- JavaScript
- Title
- document ready
- Category
- JavaScript
- Title
- enter event in jquery
- Category
- JavaScript
- Title
- filtering json array in javascript
- Category
- JavaScript
- Title
- how to send json data in fetch request body
- Category
- JavaScript
- Title
- anjular js
- Category
- JavaScript
- Title
- how to get element from arraylist react
- Category
- JavaScript
- Title
- form taglib in jsp
- Category
- JavaScript
- Title
- how to remove a property from an object in javascript
- Category
- JavaScript
- Title
- javascript call function
- Category
- JavaScript
- Title
- how to get timestamp in javascript of a date object
- Category
- JavaScript
- Title
- how to version a react app azure pipelines
- Category
- JavaScript
- Title
- bq show pretty json
- Category
- JavaScript
- Title
- angular date formats
- Category
- JavaScript
- Title
- how to remove 000webhost watermark 2019
- Category
- JavaScript
- Title
- dumpdata json model dajngo
- Category
- JavaScript
- Title
- how to make dynamic columns in jquery
- Category
- JavaScript
- Title
- chrome add a javascript bookmark
- Category
- JavaScript
- Title
- how to check reactjs version in command prompt
- Category
- JavaScript
- Title
- binary to int javascript
- Category
- JavaScript
- Title
- console.log('Hi there!');
- Category
- JavaScript
- Title
- javascript check if two date ranges overlap
- Category
- JavaScript
- Title
- generate random ip address javascript
- Category
- JavaScript
- Title
- destruct e.target.value param
- Category
- JavaScript
- Title
- fetch api based on id nodejs and mongodb
- Category
- JavaScript
- Title
- getrect javascript
- Category
- JavaScript
- Title
- AJAX JAVASCRIPT TUTORIALS
- Category
- JavaScript
- Title
- get current directory vbscript
- Category
- JavaScript
- Title
- clear formarray in angular 6
- Category
- JavaScript
- Title
- convert this to d3.select()
- Category
- JavaScript
- Title
- dynamic for loop react
- Category
- JavaScript
- Title
- edje js not pre compile for node 12 version
- Category
- JavaScript
- Title
- check undefined object javascript one liner set to emtpy
- Category
- JavaScript
- Title
- excel javascript api protect worksheet
- Category
- JavaScript
- Title
- express validator always return error
- Category
- JavaScript
- Title
- angular build production
- Category
- JavaScript
- Title
- build filter js
- Category
- JavaScript
- Title
- how to create simple node project
- Category
- JavaScript
- Title
- how to extract values from array in javascript
- Category
- JavaScript
- Title
- If 'ion-item' is an Angular component, then verify that it is part of this module.
- Category
- JavaScript
- Title
- get id of element javascript
- Category
- JavaScript
- Title
- javascript class click event
- Category
- JavaScript
- Title
- check if a key exists in an object javascript
- Category
- JavaScript
- Title
- how to use ternary operatiion in sequelize join statement
- Category
- JavaScript
- Title
- get keys of object js
- Category
- JavaScript
- Title
- declare array in javascript
- Category
- JavaScript
- Title
- bubble sort
- Category
- JavaScript
- Title
- how to check chrome version in js
- Category
- JavaScript
- Title
- get contents between tags javascript
- Category
- JavaScript