-
-
Save DavidPeralvarez/e82377d4672045d41ca3ed37422ac86b to your computer and use it in GitHub Desktop.
JavaSript - Los bucles For, For...In y ForEach
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Curso de Javascript</title> | |
</head> | |
<body> | |
<script src="scripts.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function multiplicaPor2( num ){ | |
return num * 2; | |
} | |
var numeros = [ 1, 2, 3, 4, 5 ]; | |
console.log( numeros ); | |
// for ( var i = 0; i < numeros.length; i++ ) { | |
// if( i === ( numeros.length - 1 ) ){ | |
// continue; | |
// } | |
// numeros[i] = multiplicaPor2( numeros[i] ); | |
// } | |
// numeros = numeros.map( function( el ){ | |
// return multiplicaPor2( el ); | |
// } ); | |
numeros.forEach( function( el ){ | |
console.log( multiplicaPor2( el ) ); | |
} ); | |
console.log( numeros ); | |
var obj = { | |
prop1: 'valor 1', | |
prop2: 'valor 2', | |
prop3: 'valor 3' | |
}; | |
for( prop in obj ) { | |
console.log( prop + ' : ' + obj[prop] ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment