How Do I Print The Value Of All Properties In An Object In Javascript?
i want to use a for in oop to get the value of all the properties but do not know how. The tutorial i am following gives this example of how i can do it, but i dont understand it.
Solution 1:
I suggest you to use variable name that has some meaning instead of x and y like:
for(var property in object){
console.log(object[property]);
}
for your object
for(var prop in nyc){
console.log(nyc[prop]);
}
Solution 2:
for (var propertyin obj){
console.log(property + ": " + obj[property]);
}
This should do the trick, what this does is loops through the "Properties" of the object and logs the values accordingly.
Solution 3:
A one-liner would be:
Object.entries(obj).map(([key, value]) => key + ":" value)
Post a Comment for "How Do I Print The Value Of All Properties In An Object In Javascript?"