I am getting following string from API response. I have to transform this string into a set of Array. Text and following images should be one group. Text after image should create a new group with the following images. The question is how to run a loop over HTML string.
API Response
<p>aaaaa</p>
<p><img src="img.jpg" alt="" width="369" height="224" /></p>
<p><img src="img.jpg"alt="" width="369" height="224" /></p>
<p>bbbb</p>
<p>bbbb</p>
<p><img src="img.jpg" /></p>
<p>ccc</p>"
Expected output:
[
['aaaaa', '<img src="img.jpg" alt="" width="369" height="224" />', '<img src="img.jpg"alt="" width="369" height="224" />'],
['bbbb', 'bbbb', '<img src="img.jpg" />'],
['ccc']
]
The function will be like
function makeHtmlSet(){
var htmlSet = []
for(var i=0;i<?;i++){
if(?.nodeType===Node.textNode){
htmlSet = [];
htmlSet.push(?);
}
else{
htmlSet.push(?);
}
}
}
pelements?p