📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
✅ Some premium posts are free to read — no account needed. Follow me on Medium to stay updated and support my writing.
🎓 Top 10 Udemy Courses (Huge Discount): Explore My Udemy Courses — Learn through real-time, project-based development.
▶️ Subscribe to My YouTube Channel (172K+ subscribers): Java Guides on YouTube
Example 1 - Using Object.keys() Method
// using Object Literals
var user = {
firstName : 'Ramesh',
lastName : 'Fadatare',
emailId : 'ramesh@gmail.com',
age : 29,
getFullName : function (){
return user.firstName + " " + user.lastName;
}
}
function testNumberOfProperties(){
let count = Object.keys(user).length;
console.log("Number of properties in User object is : " + count);
}
testNumberOfProperties();
Number of properties in User object is : 5
Example 2
const car = {
color: 'blue',
brand: 'Ford'
}
const prop = 'color'
function createNewObject(){
const newCar = Object.keys(car).reduce((object, key) => {
if (key !== prop) {
object[key] = car[key]
}
return object
}, {})
console.log(newCar);
}
createNewObject();
{brand: "Ford"}
Comments
Post a Comment
Leave Comment