Skip to content Skip to sidebar Skip to footer

How To Take Element From Two Json Arrays In Jquery

arr1 = [ {Lattitude: '52,4043000', Location: 'a2', Longitude: '55,7181815'}, {Lattitude: '52,3882320', Location: 'b2', Longitude: '55,7225500'}, {Lattitude: '52,4041184

Solution 1:

Try this,

functioncompareArr(arr1, arr2) {
            var longArray = arr1.length >= arr2.length ? arr1 : arr2;
            var shortArray = arr1.length < arr2.length ? arr1 : arr2;

            return resultArr = longArray.filter(function (v) {
                return shortArray.filter(function (iv) {
                    return v.Lattitude === iv.Lattitude
                            && v.Location === iv.Location
                            && v.Longitude === iv.Longitude;
                }).length === 0;
            });
        }

        var resultArr = compareArr(arr2, arr1);

Pass two array to this function in any sequense, the result will be same.

Post a Comment for "How To Take Element From Two Json Arrays In Jquery"