javascript - Comparing two arrays in jquery -


using code...

var = ['volvo','random data']; var b = ['random data']; var unique = $.grep(a, function(element) {     return $.inarray(element, b) == -1; });  var result = unique ;  alert(result);  

...i able find element of array "a" not in array "b".

now need find:

  • if element of array "a" in array "b"
  • what index in array "b"

for example "random data" in both arrays, need return position in array b 0 index.

regarding comment, here solution:

with jquery:

$.each( a, function( key, value ) {     var index = $.inarray( value, b );     if( index != -1 ) {         console.log( index );     } }); 

without jquery:

a.foreach( function( value ) {     if( b.indexof( value ) != -1 ) {        console.log( b.indexof( value ) );     } }); 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -