pour en boucle

Solutions on MaxInterview for pour en boucle by the best coders in the world

showing results for - "pour en boucle"
Charlotte
24 Oct 2016
1for (variable in object) {
2...
3}
Pietro
18 Feb 2016
1// Initialize object.
2a = { "a": "Athens", "b": "Belgrade", "c": "Cairo" }
3
4// Iterate over the properties.
5var s = ""
6for (var key in a) {
7    s += key + ": " + a[key];
8    s += "<br />";
9    }
10document.write (s);
11
12// Output:
13// a: Athens
14// b: Belgrade
15// c: Cairo
16
17// Initialize the array.
18var arr = new Array("zero", "one", "two");
19
20// Add a few expando properties to the array.
21arr["orange"] = "fruit";
22arr["carrot"] = "vegetable";
23
24// Iterate over the properties and elements.
25var s = "";
26for (var key in arr) {
27    s += key + ": " + arr[key];
28    s += "<br />";
29}
30
31document.write (s);
32
33// Output:
34//   0: zero
35//   1: one
36//   2: two
37//   orange: fruit
38//   carrot: vegetable
39
40// Efficient way of getting an object's keys using an expression within the for-in loop's conditions
41var myObj = {a: 1, b: 2, c:3}, myKeys = [], i=0;
42for (myKeys[i++] in myObj);
43
44document.write(myKeys);
45
46//Output:
47//   a
48//   b
49//   c
similar questions
queries leading to this page
pour en boucle