Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. // A custom property on an array is **not iterable**
  2.  
  3. const arr = [1,2];
  4. arr[10] = 10; // => [1, 2, undefined*8, 10]
  5. arr['ok'] = 'ok';
  6.  
  7. // for-in: enumerable properties:
  8. for (const index in arr) console.log(arr[index]); // => 1, 2, 10, 'ok'
  9. // for-of: iterable
  10. for (const value of arr) console.log(value); // => 1, 2, undefined*8, 10
  11. // forEach: strip undefined???
  12. arr.forEach(value => console.log(value)); // => 1, 2, 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement