javascript : Object .equals(Object)
javascript : Object.equals(Object)
Target:
Applicable with any javascript Object .
Description :
It compare two javascript object, array, dom element, json object, class object, date object, etc. in depth and compare its property value and return true/false whether both object structure and values are same. It is recursive method so it compare deep in object property.
Note: If both object structure is same and holding same property value then it return true otherwise false.
Syntax:
Object.equals(Object)
return true/false by comparing values of every property of objects.
Usase:
- var arr1 = [1,2,3,4,5];
var arr2 = [1,2,3,4,5];
arr1.equals(arr2);
It return true. while arr1==arr2 return false - var arr1 = [1,2,3,4,5];
var arr2 = arr1.clone();
arr1.equals(arr2);
It return true. while arr1==arr2 return false - var arr1 = [1,2,2,4,5];
var arr2 = [1,2,3,4,5];
arr1.equals(arr2);
It return false - var d1 = new Date('1/Jan/2020');
var d2 = new Date('1/Jan/2020');
d1.equals(d2);
It return true. while d1==d2 return false - var d1 = '1/Jan/2020 12:00AM'.toDateTime();
var d2 = '1/Jan/2020 12:00PM'.toDateTime();
d1.equals(d2);
It return false - var obj1 = {name:'rajkumar', gender:'male'};
var obj2 = {name:'rajkumar', gender:'male'};
obj1.equals(obj2);
It return true. while obj1==obj2 return false - var obj1 = {name:'rajkumar', gender:'male'};
var obj2 = {gender:'male', name:'rajkumar'};
obj1.equals(obj2);
It return true. while obj1==obj2 return false - var obj1 = {name:'rajkumar', gender:'male', age:23};
var obj2 = {name:'rajkumar', gender:'male'};
obj1.equals(obj2);
It return false. - var obj1 = {name:'rajkumar', gender:'male', age:23};
var obj2 = {name:'rajkumar', age:23 , gender:'male'};
obj1.equals(obj2);
It return true. - var obj1 = {name:'rajkumar', gender:'male', age:23};
var obj2 = {name:'rajkumar', age:24 , gender:'male'};
obj1.equals(obj2);
It return false. - var obj1 = [];
var obj2 = [];
obj1.equals(obj2);
It return true. while obj1==obj2 return false - var obj1 = [];
var obj2 = {};
obj1.equals(obj2);
It return false.
Download MYJS.js
MyJs
is a collection of java script extension methods that enhances the JavaScript
objects, class object, DOM element, domElementsCollections, Date, String, Number
and other data type.
Include
in you project landing page (master page) and it will extends your DOM and
JavaScript Objects.
Comments
Post a Comment