This is the code:
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)}
]
const formatted_content = {"ops":[{"attributes":{"italic":true,"bold":true},"insert":"let's"},{"insert":" write "},{"attributes":{"underline":true},"insert":"something"},{"insert":" wonderful\n"}]}
This works flawlessly:
console.log(JSON.stringify(formatted_content));
But the result of:
console.log(container_list[3].defvalue);
is undefined .
How could i assign a JSON/variable to a property in an object? Thanks!
formatted_contentafter you definecontainer_list, why would you expect that to work at all?(function() { var x = test(); function test() { return 'yes'; } console.log(x); })()will work just fine). If you copied this pattern from somewhere, please edit your post to point to where you found that pattern, because I would be incredibly surprised to learn that someone managed to write code where this did work.