Skip to content

Instantly share code, notes, and snippets.

@royling
Last active September 27, 2016 09:59
Show Gist options
  • Save royling/c6affd1012dfe75151abee43c1855e6a to your computer and use it in GitHub Desktop.
Save royling/c6affd1012dfe75151abee43c1855e6a to your computer and use it in GitHub Desktop.
JavaScript: Wat!
// 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
['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