is possible compare arrays
var maps1= [{name: triangle, value: 1},{name: square, value: 2}]; var maps2= [triangle,rectangle];
i want compare these both arrays, if object of map2 matches objects of map1 need value of map1, in above exmaple triangle matches , want value of triangle.
function identical (arr1, arr2) { if(arr1.length != arr2.length) { return false; } var exists = arr1.length; for(var = 0; i<arr1.length; i++) { for(var j =0; j<arr2.length ; j++) { if(object.keys(arr1[i]).equals(object.keys(arr2[j]))) { exists--; } } } return !exists; }
var map1= [{name: 'triangle', value: '1'},{name: 'square', value: '2'}]; var map2= ['triangle','rectangle']; var result=[]; for(i=0; i<map2.length; i++){ var comp= map2[i]; for(j=0; j<map1.length; j++){ if(map1[j].hasownproperty('name')){ if(map1[j].name == comp){ result.push(map1[j]); } } } } alert(json.stringify(result));
Comments
Post a Comment