The project I am working has many of the same kind of element on a page. This kind of element contains some text that I need to store in an array. I can easily select all these elements with JQuery and have JQuery return a result set of elements. However, I am having a really difficult understanding how to iterate through all of the elements in the result set and storing the text from each element in an array.
I was thinking maybe using something like foreach somehow?
I appreciate any help in this regard.
Many thanks in advance!
HTML
<div class="option">apples</div>
<div class="option">oranges</div>
<div class="option">peaches</div>
<div class="option">grapes</div>
JavaScript
var i = 0;
foreach($('.option').text() as x){
someArray[i] = x;
i++;
}
Desired Output
alert(someArray[0]); // apples
alert(someArray[1]); // oranges
alert(someArray[2]); // peaches
alert(someArray[3]); // grapes