How to print object in Node JS

前端 未结 6 2044
忘掉有多难
忘掉有多难 2020-12-18 22:49

In the below code (running on Node JS) I am trying to print an object obtained from an external API using JSON.stringify which results in an error:

6条回答
  •  醉话见心
    2020-12-18 23:41

    This can print the key of the object and the value of the object in the simplest way. Just try it.

    const jsonObj = {
      a: 'somestring',
      b: 42,
      c: false
    };
    
    Array.from(Object.keys(jsonObj)).forEach(function(key){
      console.log(key + ":" + jsonObj[key]);
    });
    

提交回复
热议问题