committed by
Huyen Nguyen
parent
b344ca8602
commit
b2ab72cb0b
@ -18,14 +18,15 @@ for (variable in object) {
|
|||||||
## Examples
|
## Examples
|
||||||
```js
|
```js
|
||||||
// Initialize object.
|
// Initialize object.
|
||||||
var a = { "a": "Athens", "b": "Belgrade", "c": "Cairo" };
|
const a = { "a": "Athens", "b": "Belgrade", "c": "Cairo" };
|
||||||
|
|
||||||
// Iterate over the properties.
|
// Iterate over the properties.
|
||||||
var s = "";
|
let s = "";
|
||||||
for (var key in a) {
|
for (let key in a) {
|
||||||
s += key + ": " + a[key];
|
s += key + ": " + a[key];
|
||||||
s += "<br />";
|
s += "<br />";
|
||||||
}
|
}
|
||||||
|
|
||||||
document.write (s);
|
document.write (s);
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
@ -34,15 +35,15 @@ document.write (s);
|
|||||||
// c: Cairo
|
// c: Cairo
|
||||||
|
|
||||||
// Initialize the array.
|
// Initialize the array.
|
||||||
var arr = new Array("zero", "one", "two");
|
let arr = new Array("zero", "one", "two");
|
||||||
|
|
||||||
// Add a few expando properties to the array.
|
// Add a few expando properties to the array.
|
||||||
arr["orange"] = "fruit";
|
arr["orange"] = "fruit";
|
||||||
arr["carrot"] = "vegetable";
|
arr["carrot"] = "vegetable";
|
||||||
|
|
||||||
// Iterate over the properties and elements.
|
// Iterate over the properties and elements.
|
||||||
var s = "";
|
let s = "";
|
||||||
for (var key in arr) {
|
for (let key in arr) {
|
||||||
s += key + ": " + arr[key];
|
s += key + ": " + arr[key];
|
||||||
s += "<br />";
|
s += "<br />";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user