Jeremy G.

asked • 05/10/21

Dynamically generate innerHTML elements from a response array (Javascript)


****This is a part of my code:

var arr1 = response;

console.log(arr1);



****This is the response/console logged arr1:

{

"channels": {

"1620184778889x527731420801269760": [

{

"channel": "1620184778889x527731420801269760",

"timetoken": "16204064644032062",

"message": {

"content": "44444444444",

"sender": "Jeremy"

},

"messageType": null,

"uuid": "1617237881603x986210451354598100"

}

],

"1618599897203x154294096401530880": [

{

"channel": "1618599897203x154294096401530880",

"timetoken": "16203351496721278",

"message": {

"content": "fffffffdd",

"sender": "Jeremy"

},

"messageType": null,

"uuid": "1617237881603x986210451354598100"

}

],

"1618613571551x955443898854408200": [

{

"channel": "1618613571551x955443898854408200",

"timetoken": "16204261556065826",

"message": {

"content": "78777",

"sender": "Jeremy"

},

"messageType": null,

"uuid": "1617237881603x986210451354598100"

}

]

}

}


****This is what I need:

I need to get the following data

1.channel

2.timetoken

3.message > content

4.message > sender


And then I need to dynamically generate an innerHTML property for each channel in the array (the amount of channels will frequently vary).


Something like this for each channel returned (incorrect syntax, just an example)


document.getElementById(*channel*).innerHTML = *sender* + ' ' + *content* + ' ' + *timetoken*;



Thank you, I'm not familiar with JavaScript syntax and am having trouble adapting any solutions I find to match this.


2 Answers By Expert Tutors

By:

Josh R. answered • 05/20/21

Tutor
5 (3)

Full-Stack Ruby/Javascript Developer

Dan B. answered • 05/11/21

Tutor
5 (20)

Experienced University Level Tutor in Software Engineering

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.