function to find the unique elements from two arrays
var array3 = array1.filter(function(obj) { return array2.indexOf(obj) == -1; });
function to find the unique elements from two arrays
var array3 = array1.filter(function(obj) { return array2.indexOf(obj) == -1; });
Get all non-unique values (i.e.: duplicate/more than one occurrence) in an array
const arrayNonUniq = array => {
if (!Array.isArray(array)) {
throw new TypeError("An array must be provided!")
}
return array.filter((value, index) => array.indexOf(value) === index && array.lastIndexOf(value) !== index)
}
arrayNonUniq([1, 1, 2, 3, 3])
//=> [1, 3]
arrayNonUniq(["foo", "foo", "bar", "foo"])
//=> ['foo']
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us