hello all, how do I create an Array of a list of items from a webpage like say; a web page contains list(ordered pr unordedred) of countries and I want to create an Array with those countries. know that, I don't know the Number of countries available at the page. so I want my code to get the Number of countries and create an array with them.
Just find whatever container has the countries you want, and do something like this: (assuming the countries are in a list with an id matching #countrylist tag) $(document).ready(function() { var countryList = []; $('#countrylist li').each(function() { countryList.push($(this).text()); }); console.log(countryList); }); Code (markup): That will iterate through each list-item in the ul, and add the text from the list-item to the array.