Marquis Wang's may well be the best answer when using jQuery.
Here is something quite similar in pure JavaScript, using JavaScript's forEach
method. forEach takes a function as an argument. That function will then be called for each item in the array, with said item as the argument.
Short and easy: