Last active
August 29, 2015 14:10
-
-
Save kichiemon/f1dcd8ee9ffc3bea0b36 to your computer and use it in GitHub Desktop.
[Spider]Swiftと同じfor-in型がJavascriptで書けます ref: http://qiita.com/iKichiemon/items/3fcb78d5da5af15ef1eb
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
| let foods:[String] = ["apple", "fish", "meat"] | |
| for food in foods { | |
| println(food) | |
| } | |
| // "apple" | |
| // "fish" | |
| // "meat" | |
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
| var foods = ["apple", "fish", "meat"] | |
| for food in foods { | |
| console.log(food) | |
| } | |
| // "apple" | |
| // "fish" | |
| // "meat" | |
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
| for food, i in foods { | |
| console.log("I like \(foods[i])."); | |
| }; | |
| // "apple" | |
| // "fish" | |
| // "meat" | |
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
| var man:[String] = { | |
| "name" : "ken" , | |
| "age" : 18, | |
| "address" : "Japan" | |
| }; | |
| for key, value of man { | |
| console.log("\(key) : \(valu)."); | |
| } | |
| // "name : ken" | |
| // "age : 18" | |
| // "address : Japan" | |
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
| var lists = [ 1, 2, 3, 5, 6, 7, 8, 9, 10 ]; | |
| var doubles = [ value * 2 for value in lists ]; | |
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
| foods.forEach(function (food) { | |
| console.log(food); | |
| }, this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment