mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Merge pull request #3148 from hamidra/hamid/js
[javascript/en] add for/of loops
This commit is contained in:
commit
d27199d001
@ -266,6 +266,15 @@ for (var x in person){
|
||||
description += person[x] + " ";
|
||||
} // description = 'Paul Ken 18 '
|
||||
|
||||
// The for/of statement allows iteration over iterable objects (including the built-in String,
|
||||
// Array, e.g. the Array-like arguments or NodeList objects, TypedArray, Map and Set,
|
||||
// and user-defined iterables).
|
||||
var myPets = "";
|
||||
var pets = ["cat", "dog", "hamster", "hedgehog"];
|
||||
for (var pet of pets){
|
||||
myPets += pet + " ";
|
||||
} // myPets = 'cat dog hamster hedgehog '
|
||||
|
||||
// && is logical and, || is logical or
|
||||
if (house.size == "big" && house.colour == "blue"){
|
||||
house.contains = "bear";
|
||||
|
Loading…
Reference in New Issue
Block a user