////////////////**************OBJECTS part 2 IN JS **********//////////////////// ////////// singleton objects //const tinderuser = new Object() const tinderUser ={} // assingning a function tinderUser.id = "123abc" // putting value in function tinderUser.name = "sammy " // putting value in function tinderUser.isloggedin = false // putting value in function console.log(tinderUser); // { id: '123abc', name: 'sammy ', isloggedin: false } console.log(tinderUser.name); // sammy /// nested functions const regularuser ={ email: "some@gmail.com", fullname: { userfullname: { firstname: "hitesh", lastname: "sharma" } } } //console.log(regularuser); console.log(regularuser.fullname.userfullname.firstname);/// hitesh //// combining 2 objects together into a single object const obj1 = { 1: "a" , 2: "b" } const obj2 = { 3: "a" , 4: "b" } const obj4 = { 5: "a" , 6: "b" } //// assingnuing function ////const obj3 = Object.assign({}, obj1 , obj2 , obj4) // syntax {} means target amd obj1 obj2 obj4 all three are source /// drop function //const obj5 = {...obj1, ...obj2, ...obj4}; //console.log(obj5); /// methods inside arrays const users = [ { id: 1, name: "tanishq dhingra " }, { id: 1, name: "tanishq dhingra " }, { id: 1, name: "tanishq dhingra " } ] console.log(users[1].id); // function for getting the keys present in objects console.log(Object.keys(tinderUser)); // function for getting the values present in objects console.log(Object.values(tinderUser)); // function for getting the entries present in objects console.log(Object.entries(tinderUser)); // function for checking properties present in objects and it will give answer in boolean console.log(tinderUser.hasOwnProperty('isLoggedIn'));
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter