How do I insert random words in the content line below? for eg : I want to insert hey, hello, hi in
{
"content": ""
}
and it prints
{
"content": "hey"
}
{
"content": "hello"
}
{
"content": "hi"
}
Set value to the object by method
myObj[property] = value;
let obj = {};
const randomWordsArr = ["Hey", "Hello", "Hi"];
randomWordsArr.forEach((item)=>{
obj["content"] = item;
console.log(obj);
});
I'm not sure if you're using Python or JS but if it is Python, there are several ways to do this depending on how clean you want it to be. The least clean and fastest option would be to use string manipulation. A better approach would be to maintain a dictionary which will allow you to switch around the value of content as much as you like, after which you can convert the dictionary to Json:
dictionary ={
"content": ""
}
dictionary["content"] = "hey"
json_object = json.dumps(dictionary)
print(json_object)
Your object must have a key be string and value be array. Like below these.
{
"key" : []
}
After that you can add all of the things in an Array value e.g.:
{
"key" : ["hi","hello","hey"]
}
And this is how to add some thing to your Array.
let obj = {}
obj.key = []
obj.key.push("hi")
obj.key.push("hello")
obj.key.push("hey")
//and show console
console.log(obj.key)
//Your can see
["hi","hello","hey"]