I want to get unique values from two different arrays.
Two arrays are as below in JavaScript:
<script>
var a=new Array;
var b=new Array;
a={'a','b','c','d','e'}
b={'a','d','e','c'}
</script>
I want output like:
new array => {'a','c','d','e'}
How can I find unique records from both arrays using JavaScript prototype function or jQuery function?
I don’t know if you have the terms correct. Unique values to me would be members which appear only once in either array. It seems you want members that are present in both arrays (common values, or intersection), based on your example.
You can use jQuery to handle this.
grep()is your friend.You could do this without jQuery, but I’m not sure if the native
filter()andindexOf()methods have the best browser support.With underscore it’s easy at
_.intersection(arr1, arr2).jsFiddle.