var user = { id: 1, firstName: 'Ramesh', lastName: 'Fadatare', emailId: 'ramesh@gmail.com', age: 29, address: { street: 'kondhwa', pincode: '12345' } }
console.log('This is object'+ user); // wrong way
This is object[object Object]
console.log('This is object', user); // correct way
console.log('This is object -> ' + JSON.stringify(user)); // this also works
Complete Example
function test() {
var user = {
id: 1,
firstName: 'Ramesh',
lastName: 'Fadatare',
emailId: 'ramesh@gmail.com',
age: 29,
address: {
street: 'kondhwa',
pincode: '12345'
}
}
console.log('This is object'+ user); // wrong way
console.log('This is object', user); // correct way
console.log('This is object -> ' + JSON.stringify(user)); // this also works
}
test();
This is object[object Object]
This is object {id: 1, firstName: "Ramesh", lastName: "Fadatare", emailId: "ramesh@gmail.com", age: 29, …}
This is object -> {"id":1,"firstName":"Ramesh","lastName":"Fadatare","emailId":"ramesh@gmail.com","age":29,"address":{"street":"kondhwa","pincode":"12345"}}
Continue Learning with Java Guides
Want to take your programming skills to the next level? Explore my practical Udemy courses on Java, Spring Boot, Microservices, Full-Stack Development, Docker, and Generative AI. You can also follow my structured learning roadmaps to become a professional developer.
By Ramesh Fadatare - Udemy Instructor Partner
Comments
Post a Comment
Leave Comment