Using jQuery's inArray method with a JavaScript associative array (or object) -


it's possible i'm not using jquery's inarray() function, have construct object has indexes of 2 other javascript objects values match exactly:

var arr1 = {     a: "alfa",     b: "beta"}; var arr2 = {b: "beta"}; alert(jquery.inarray(arr2, arr1)); 

here, expect object contains only:

{b: "beta"} 

similarly, if arrays looked this:

var arr1 = {     a: "alfa",     b: "beta",     c: "test"}; var arr2 = {b: "beta",             c: "not same value"}; 

i still expect:

{b: "beta"} 

because values in c index not same.

thanks in advance, ciao h.

try this:

http://jsfiddle.net/treeface/u5xdz/1/

the idea here loop on arr1 object , see if similar index exists in arr2, , if index's value in arr1 matches index's value in arr2.

var arr1 = {         a: "alfa",         b: "beta"     },     arr2 = {b: "beta"},     combinedarr = {};   $.each(arr1, function(ind, el) {     if (typeof arr2[ind] !== 'undefined' && arr1[ind] === arr2[ind])         combinedarr[ind] = el; });  console.log(combinedarr); 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -