Convert JS object to JSON string

后端 未结 27 2533
庸人自扰
庸人自扰 2020-11-22 00:43

If I defined an object in JS with:

var j={\"name\":\"binchen\"};

How can I convert the object to JSON? The output string should be:

27条回答
  •  再見小時候
    2020-11-22 01:35

    Use the JSON.stringify() method:

    const stringified = JSON.stringify({})  // pass object you want to convert in string format
    

提交回复
热议问题