question about how to use .each() the right way

I want to find all divs with a class of 'addressLocation' within a div with an id of orders. I want to get the text inside each of the returned divs, and append it to a "waypoints" variable, and I'm not doing it the right way. I'm a little confused about the array and accessing objects in it. Here's my code. I'm hoping this is really easy, but I don't know how to do it correctly. Thanks a bunch.
var waypoints = "";
var addressArray = $("#orders").find('.directionsAddress');
    $.each(addressArray, function (index, address) {
        waypoints = waypoints + "|" + addressArray[index].text();
    });

Open in new window

LVL 9
BobHavertyComhAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rainer JeschorCommented:
Hi,
not sure, but the following code should work:
var waypoints = "";
    $("div.directionsAddress",$("#orders")).each(function() {
	    waypoints = waypoints + "|" + $(this).text();
	});

Open in new window

Live sample:
http://jsfiddle.net/EE_RainerJ/zd7h7Lch/

HTH
Rainer
Julian HansenCommented:
This is probably the most standard way of doing it.

var waypoints = '';
$('#orders div.addressLocation').each(function() {
   waypoints += "|" + $(this).text();
});

Open in new window


Full listing here
<!doctype html>
<html>
<head>
<title>Test</title>
<style type="text/css">
</style>
</head>
<body>
<div>
  <div class="addressLocation">
    Not this one
  </div>
</div>
<div id="orders">
  <div class="addressLocation">
    this one
  </div>
  <div class="addressLocation">
    another one
  </div>
  <div class="addressLocation">
    last one
  </div>
</div>
<div id="result"></div>
</body>  
<script src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
$(function() {
  var waypoints = '';
  $('#orders div.addressLocation').each(function() {
     waypoints += "|" + $(this).text();
  });
  $('#result').html(waypoints);
}
</script>
</body>
</html>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BobHavertyComhAuthor Commented:
Thanks guys.
Julian HansenCommented:
You are welcome - thanks for the points.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.