Problem when traversing an array in javascript

0

I have the following problem when traversing an array from javascript

Var arreglo = [1,2,3];

Arreglo.map(function( item , index ) {
 // en la primera iteracion el valor de item es undefined

Console.log(item);

// y quisiera saber como hago para qye no se muestre el mensaje undefined en su primera iteracion
});
    
asked by Code tutoriales 21.12.2017 в 21:54
source

2 answers

1

You have two errors;

  

1- Below you call Fix instead of Fix which is what you define.

     

2- The reserved word var is lowercase

correctly it would be like this:

    var arreglo = [1,2,3];

        arreglo.map(function( item,index) {
        console.log(item);
     });
    
answered by 21.12.2017 в 22:02
1

Friend you have to put the literal variables for example put:

Var arreglo = [1,2,3]

and it's

var arreglo = [1,2,3]
  

the var goes in lowercase because it is a reserved word of javascript.

Also the variable that you put

var arreglo

and then you call it with

Arreglo.map(function( item , index ) { 
 console.log(item);
});
  

The error is in uppercase, friend if you put var Avion when calling pon Avion equal.

Another detail is when putting

Console.log(...)

the function is used like this

console.log(...) 
  

With the letter ( c ) in lowercase.

Functional example

var arreglo = [1,2,3];

arreglo.map(function( item , index ) { 

console.log(item);

 });
    
answered by 21.12.2017 в 21:59