ES6 JavaScript
In this ES6 tutorial we are going to learn about Object static methods like keys, values and entries.
Let's say we have the following object with some properties.
const user = {
username: 'yusufshakeel',
isOnline: true,
score: 10,
lastThreePoints: [6,7,8],
profiles: {
youtube: 'https://www.youtube.com/@yusufshakeel'
}
};
To get all the keys in the object we use the Object.keys() static method.
const keys = Object.keys(user);
console.log(keys);
To get all the values of the keys in the object we use the Object.values() static method.
const values = Object.values(user);
console.log(values);
To print all the key-value pairs in the object we use the Object.entries static method.
const entries = Object.entries(user);
console.log(entries);
Alright this brings us to the end of another tutorial. See you soon. Have fun coding.
ADVERTISEMENT