instance of object in javascript code example

Example 1: instance of

The instanceof keyword checks whether an object
is an instance of a specific class or an interface.
The instanceof keyword compares the
instance with type. The return value
is either true or false .

Example 2: js class check if new instance

new Date() instanceof Date;  // => true

Example 3: if property is same group javscript

var xobj = [
    { role:"Organize Admin", role_id:"id1", permission_name:"View All Users",active: "true" },
    { role:"Organize Admin", role_id:"id1", permission_name:"Create users", active: "true" },
    { role:"Organize Admin", role_id:"id1", permission_name:"Edit users", active: "true" },
    { role:"System Admin", role_id:"id2", permission_name:"Edit users", active: "true" },
    { role:"System Admin", role_id:"id2", permission_name:"Edit users", active: "true" },
];
var groups = {};
xobj.forEach(obj => {	
    if(!groups.hasOwnProperty(obj.role_id)){
        groups[obj.role_id] = [];
    }
    groups[obj.role_id].push(obj);
})
console.log(groups)

Tags:

Java Example