What is the suggested way to solve this issue?
I have a HTML list like so:
<ul>
<li><img src="img1.jpg" alt="Image One" /></li>
<li><img src="img2.jpg" alt="Image Two" /></li>
<li><img src="img3.jpg" alt="Image Three" /></li>
</ul>
and I’d like to convert this data to an object, something like:
{
images: {
1: {
src: "img1.jpg",
alt: "Image One"
},
2: {
src: "img2.jpg",
title: "Image Two"
},
3: {
src: "img3.jpg",
title: "Image Three"
}
}
}
Thank you
Here’s one way to do it.
I explained how it works in the comments.
Please tell me if there’s anything wrong with the code.