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"
}
Advertisement
Answer
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);
});