DEV Community

_Khojiakbar_
_Khojiakbar_

Posted on • Edited on

Object methods 🦜

let result;
const userProfile = {
        username: 'Khojiakbar',
        age: 26,
        job: 'programmer',
        city: 'Tashkent region',
}
Enter fullscreen mode Exit fullscreen mode

// Object.keys()
result = Object.keys(userProfile);

// Object.values()
result = Object.values(userProfile);

// Object.entries()
result = Object.entries(userProfile) // returning nested array

// Object.fromEntries()
let fromEntries = Object.fromEntries(result)

console.log(result);
console.log(fromEntries);
Enter fullscreen mode Exit fullscreen mode
// Object.freeze()
Object.freeze(userProfile);

// Add -
userProfile.weight = 80
// Modify -
userProfile.username = 'Bilol'
// Delete -
delete userProfile.city
// NO AMD
console.log(userProfile);
Enter fullscreen mode Exit fullscreen mode
// Object.isFrozen()
result = Object.isFrozen(userProfile)
console.log(result);
Enter fullscreen mode Exit fullscreen mode
// Object.seal()
result = Object.seal(userProfile);

// Add -
userProfile.weight = 80;
// Modify +
userProfile.age = 33;
// Delete -
delete userProfile.city;
// NO AD
console.log(userProfile);
Enter fullscreen mode Exit fullscreen mode
// Object.isSealed()
result = Object.isSealed(userProfile)
console.log(result);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)