Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript AJAX Basics (retiring) Programming AJAX Processing JSON Data

Miguel Nunez
Miguel Nunez
3,266 Points

Whats the difference between the .length use in for loops in ajax and the .length use for number output?

Hey guys I asked this question at stackoverflow please look at this link because i'm not happy with the answers i'm getting in return on that site please respond back here if you know the answer thank you.

https://stackoverflow.com/questions/45605705/whats-the-difference-between-the-length-use-in-for-loops-in-ajax-and-the-lengt

1 Answer

Hi,

The answers posted on Stack Overflow seem accurate. The .length property returns a count i.e. an integer of a target value/object.

So for example, an Array with 4 items in it will return the number 4 when you access it's .length property - https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/length

A function that takes n parameters as arguments, will return n when you access its .length property - https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Function/length

As you pointed out on Stack Overflow for Strings, your example of "Steve".length will return 5 - https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/length

Hope this helps

Miguel Nunez
Miguel Nunez
3,266 Points

I know that I know it gives you a count back as an output but in that ajax example why didn't it gave me a numerical response back but instead it gave names of people can you explain that? That's what i'm confused about.

I can see that your Stack Overflow question has a new answer. Does it answer your question?