Issue
I'm working on API, which extracts data from a web site. and the website is like - >
<div id="mainContainer">
<a class="item">text1</a>
<a class="item">text2</a>
<a class="item">text3</a>
<a class="item">text4</a>
<a class="item">text5</a>
</div>
I want to store all text in an object like {"item1":"text1","item2":"text2"......}; here is what I'm doing
var prediction = $('#mainContainer > item');
console.log(prediction);
output
<a class="item">text1</a><a class="item">text2</a><a class="item">text3</a>....
How do I do it ??
Solution
You can create an object and then populate it with an each
values = {};
$('#mainContainer a.item').each((i,x) => values['item'+(i+1)] = $(x).text())
Answered By - mapr
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.