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