Assigning a JSON object as string to a property in an object in Javascript

Swap the sequence you declare these 2 constants. When you declare container_list, formatted_content is not yet defined





const formatted_content = {"ops":[{"attributes":{"italic":true,"bold":true},"insert":"let's"},{"insert":" write "},{"attributes":{"underline":true},"insert":"something"},{"insert":" wonderful\n"}]}

var container_list = [
{type: 'editor', id: 't1', placeholder: 'first section'},
{type: 'onlytext', value: 'second section - only text'},
{type: 'editor', id: 't2', placeholder: 'third section'},
{type: 'editor', id: 't3', placeholder: 'fourth section', defvalue: JSON.stringify(formatted_content)}
]

console.log(JSON.stringify(formatted_content));

console.log(container_list[3].defvalue);




More: