Filter unique element in array based on subarray property - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

Filter unique element in array based on subarray property

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from  ww w  . j a v  a2 s  . c o m*/
var arr = [
    ["foo", "one"],
    ["baz", "two"],
    ["bar", "one"],
    ["baz", "two"],
    ["bar", "one"],
    ["qux", "two"]
];
var seenit = [];
var n = arr.filter(function(it){ var result = seenit.indexOf(it[1]) === -1; seenit.push(it[1]); return result; });
console.log(n);
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials