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
Post a Comment