Skip to content

Instantly share code, notes, and snippets.

@msteckyefantis
Last active May 1, 2016 16:34
Show Gist options
  • Save msteckyefantis/76ab334fc85470da384768f5934f0c88 to your computer and use it in GitHub Desktop.
Save msteckyefantis/76ab334fc85470da384768f5934f0c88 to your computer and use it in GitHub Desktop.
NodeJs Lesson: "in" and "of" used with for loops.
'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
*/
@msteckyefantis
Copy link
Author

msteckyefantis commented May 1, 2016

See vandium.io for AWS Lambda developer tools. Vandium makes coding for AWS Lambda more simple and more secure. (medium article about it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment