Loop the loop


Here's my code:-

// Our Person constructor
Person= function(name,age){
this.name = name;
this.age = age;

// Now we can make an array of people
var family = new Array();
family[0] = new Person("alice",40);
family[1] = new Person("bob",42);
family[2] = new Person("michelle",8);
family[3] = new Person("timmy", 6);
// loop through our new array
for(var i = 0;i console.log(family[i].name);

now see the semicolon i used in the last to end for loop, i prefer to use or not in both cases this code works. Can anyone help me to spot the difference.


var numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
you created a numbers Array.

To get the 1st Array-Element of the numbers Array
you use

and to get all Elements with a for-loop you will have to start
at Element-zero

for (var x = 0; x < numbers.length ; x++ ) {
   console.log( number[x] );



@leonhard_wettengmx_n Thanks i got that..

but my isue was about the use of semicolon( ; ), to use or not??


but your FOR-loop usage is invalid !!!!


@leonhard_wettengmx_n what's d problem with it??


Could you please edit your Original POST

  • select your code in the Post
  • then =click= on the </>-symbol-of-this-editor

Your code will then be in a pre-code state
and you will be able to make/present the proper indentations.

I think the < sign caused the strange Display of your FOR-loop.
Coud you please try....