Skip to content

Instantly share code, notes, and snippets.

@DavidPeralvarez
Created April 8, 2020 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidPeralvarez/e82377d4672045d41ca3ed37422ac86b to your computer and use it in GitHub Desktop.
Save DavidPeralvarez/e82377d4672045d41ca3ed37422ac86b to your computer and use it in GitHub Desktop.
JavaSript - Los bucles For, For...In y ForEach
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Curso de Javascript</title>
</head>
<body>
<script src="scripts.js"></script>
</body>
</html>
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