I have some HTML like this..
<div class="item">
<div class="title">Product 1</div>
<div class="price">34</div>
<div class="color">Red</div>
</div>
<div class="item">
<div class="title">Product 2</div>
<div class="price">3</div>
<div class="color">Green</div>
</div>
<div class="item">
<div class="title">Product 4</div>
<div class="color">Yellow</div>
</div>
I am trying to create an array of objects in JavaScript / jQuery like this..
var output = [];
$('.item').each(function(i, obj) {
let row = {
"title": "title",
"price": "price",
"color": "color"
}
output.push(row);
});
In my example I don't know how to get the title price and color, also how can I set an empty value if they do not exist in my original HTML?
"title": $(this).find(".title").text()