I want to remove the same values from two tables such as:
var array1 = ["1", "2", "3", "4", "5"]
var array2 = ["3", "4", "5"]
And I want to result :
var result = ["1", "2"]
I want to remove the same values from two tables such as:
var array1 = ["1", "2", "3", "4", "5"]
var array2 = ["3", "4", "5"]
And I want to result :
var result = ["1", "2"]
You can use filter
and include
var array1 = ["1", "2", "3", "4", "5"]
var array2 = ["3", "4", "5"]
array1.filter((a) => { return !array2.includes(a)});
Use filter
and invert the return from includes
:
var array1 = ["1", "2", "3", "4", "5"]
var array2 = ["3", "4", "5"]
var result = array1.filter(e => !array2.includes(e));
console.log(result);
You can use filter()
and includes()
and concat()
. It will work for both arrays
var array1 = ["1", "2", "3", "4", "5"]
var array2 = ["3", "4", "5","6"]
let result = array1.filter(x => !array2.includes(x)).concat(array2.filter(x => !array1.includes(x)))
console.log(result);