Finding the length of arrays (and strings)

Sometimes you might need to find out how many elements exist in an array (that is, the length of the array). The sample code below shows exactly how to do that, and it also shows you how to find the length of a string using pretty much the same method.

The video here also explains how to do this.

<!DOCTYPE html>
<html lang="en"
 <meta charset="utf-8"/>
 <title>JavaScript - More Arrays</title>
 <script type="text/javascript">
 var cars = new Array();
 // to find the length (number of elements) of an array we can use arrayname.length eg.:
 We could also use the length method on a string like this:
 var word = "hello";