Last active
September 27, 2016 09:59
-
-
Save royling/c6affd1012dfe75151abee43c1855e6a to your computer and use it in GitHub Desktop.
JavaScript: Wat!
This file contains hidden or 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
// A custom property on an array is **not iterable** | |
const arr = [1,2]; | |
arr[10] = 10; // => [1, 2, undefined*8, 10] | |
arr['ok'] = 'ok'; | |
// for-in: enumerable properties: | |
for (const index in arr) console.log(arr[index]); // => 1, 2, 10, 'ok' | |
// for-of: iterable | |
for (const value of arr) console.log(value); // => 1, 2, undefined*8, 10 | |
// forEach: strip undefined??? | |
arr.forEach(value => console.log(value)); // => 1, 2, 10 |
This file contains hidden or 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
['1','2','3'].map(parseInt) // => [1, NaN, NaN] | |
// map callback: function(value:any, index:any, arr:[]):any | |
// parseInt: function(value:string, radix:number):number | |
['1','2','3'].map(num => parseInt(num, 10)) // => [1, 2, 3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment