How do i print the value of all properties in an object in javascript?

后端 未结 2 1751
终归单人心
终归单人心 2021-01-16 23:43

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 underst

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-17 00:05

    for (var property in 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.

提交回复
热议问题