javascript get array difference
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:
- devexpress dxdatagrid custom text field link
- document jquery
- how to prevent previous radio button active react native
- js create object url base64 pdf binary
- boton de copiar en html y js
- linkedin api nodejs tutorial
- Javascript check if undefined
- devexpress gridview add new row without datasource
- js loop over array of objects extract value
- comment dire le nombre de ligne html en cliquamt sur un boutton javascript
- how to import jquery in js file
- array differenc javascript
- string contains js
- Property 'find' does not exist on type NodeListOf
- jquery make readonly textbox
- js null is object typeof
- javascript create element in a new line
- react history listen get previous location
- number to array js
- copy to clipboard function javascript
- express post request body undefined
- javascript loop object
- online javascript compiler
- vue js cdn