How do I insert random words in the content line below? for eg : I want to insert hey, hello, hi in
JavaScript
x
4
1
{
2
"content": ""
3
}
4
and it prints
JavaScript
1
4
1
{
2
"content": "hey"
3
}
4
JavaScript
1
4
1
{
2
"content": "hello"
3
}
4
JavaScript
1
4
1
{
2
"content": "hi"
3
}
4
Advertisement
Answer
Set value to the object by method
myObj[property] = value;
JavaScript
1
7
1
let obj = {};
2
const randomWordsArr = ["Hey", "Hello", "Hi"];
3
4
randomWordsArr.forEach((item)=>{
5
obj["content"] = item;
6
console.log(obj);
7
});