Last active
May 1, 2016 16:34
-
-
Save msteckyefantis/76ab334fc85470da384768f5934f0c88 to your computer and use it in GitHub Desktop.
NodeJs Lesson: "in" and "of" used with for loops.
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
'use strict'; | |
const obj = { | |
obj_key_1: 'obj_value_1', | |
obj_key_2: 'obj_value_2', | |
obj_key_3: 'obj_value_3' | |
}; | |
const arr = [ 'array_value_1', 'array_value_2', 'array_value_3' ]; | |
for( let key in obj ) { | |
console.log( key ); | |
} | |
for( let key in obj ) { | |
let value = obj[ key ]; | |
console.log( value ); | |
} | |
for( let index in arr ) { | |
console.log( index ); | |
} | |
for( let value of arr ) { | |
console.log( value ); | |
} | |
/* | |
running this file in node logs the following: | |
obj_key_1 | |
obj_key_2 | |
obj_key_3 | |
obj_value_1 | |
obj_value_2 | |
obj_value_3 | |
0 // these numbers are the array indicies | |
1 | |
2 | |
array_value_1 | |
array_value_2 | |
array_value_3 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See vandium.io for AWS Lambda developer tools. Vandium makes coding for AWS Lambda more simple and more secure. (medium article about it)