js-apis-lightweightset.md 16.0 KB
Newer Older
G
Gloria 已提交
1
# @ohos.util.LightWeightSet (Nonlinear Container LightWeightSet)
W
wusongqing 已提交
2

W
wusongqing 已提交
3 4
> **NOTE**
>
W
wusongqing 已提交
5
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
W
wusongqing 已提交
6

W
wusongqing 已提交
7 8 9 10 11 12 13 14 15
**LightWeightSet** stores a set of values, each of which must be unique.

**LightWeightSet** is based on generics and uses a lightweight structure. Its default initial capacity is 8, and it has the capacity doubled in each expansion.

The values in such a set are searched using hash values, which are stored in an array.

Compared with **[HashSet](js-apis-hashset.md)**, which can also store values, **LightWeightSet** occupies less memory.

**Recommended use case**: Use **LightWeightSet** when you need a set that has only unique elements or need to deduplicate a set.
W
wusongqing 已提交
16

G
Gloria 已提交
17 18 19
This topic uses the following to identify the use of generics:
- T: Type

W
wusongqing 已提交
20 21
## Modules to Import

W
wusongqing 已提交
22
```ts
W
wusongqing 已提交
23
import LightWeightSet from '@ohos.util.LightWeightSet';  
W
wusongqing 已提交
24 25 26 27 28 29
```

## LightWeightSet

### Attributes

W
wusongqing 已提交
30 31
**System capability**: SystemCapability.Utils.Lang

W
wusongqing 已提交
32 33
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
34
| length | number | Yes| No| Number of elements in a lightweight set (called container later).|
W
wusongqing 已提交
35 36 37 38 39 40 41 42


### constructor

constructor()

A constructor used to create a **LightWeightSet** instance.

W
wusongqing 已提交
43 44
**System capability**: SystemCapability.Utils.Lang

G
Gloria 已提交
45 46 47 48 49 50 51 52
**Error codes**

For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).

| ID| Error Message|
| -------- | -------- |
| 10200012 | The LightWeightSet's constructor cannot be directly invoked. |

W
wusongqing 已提交
53 54
**Example**

W
wusongqing 已提交
55
```ts
W
wusongqing 已提交
56 57 58 59 60 61 62 63
let lightWeightSet = new LightWeightSet();
```


### isEmpty

isEmpty(): boolean

W
wusongqing 已提交
64 65 66
Checks whether this container is empty (contains no element).

**System capability**: SystemCapability.Utils.Lang
W
wusongqing 已提交
67 68 69 70 71 72 73

**Return value**

| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the container is empty; returns **false** otherwise.|

G
Gloria 已提交
74 75 76 77 78 79 80 81
**Error codes**

For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).

| ID| Error Message|
| -------- | -------- |
| 10200011 | The isEmpty method cannot be bound. |

W
wusongqing 已提交
82 83
**Example**

W
wusongqing 已提交
84
```ts
W
wusongqing 已提交
85 86 87 88 89 90 91 92
const lightWeightSet = new LightWeightSet();
let result = lightWeightSet.isEmpty();
```

### add

add(obj: T): boolean

W
wusongqing 已提交
93 94 95
Adds an element to this container.

**System capability**: SystemCapability.Utils.Lang
W
wusongqing 已提交
96 97 98 99 100

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
W
wusongqing 已提交
101
| obj | T | Yes| Target element.|
W
wusongqing 已提交
102 103 104 105 106

**Return value**

| Type| Description|
| -------- | -------- |
W
wusongqing 已提交
107
| boolean | Returns **true** if the element is added successfully; returns **false** otherwise.|
W
wusongqing 已提交
108

G
Gloria 已提交
109 110 111 112 113 114 115 116
**Error codes**

For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).

| ID| Error Message|
| -------- | -------- |
| 10200011 | The add method cannot be bound. |

W
wusongqing 已提交
117 118
**Example**

W
wusongqing 已提交
119
```ts
W
wusongqing 已提交
120
let lightWeightSet = new LightWeightSet();
G
Gloria 已提交
121
let result = lightWeightSet.add("squirrel");
W
wusongqing 已提交
122 123 124 125 126 127 128
```


### addAll

addAll(set: LightWeightSet<T>): boolean

W
wusongqing 已提交
129 130 131
Adds all elements in a **LightWeightSet** instance to this container.

**System capability**: SystemCapability.Utils.Lang
W
wusongqing 已提交
132 133 134 135 136

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
W
wusongqing 已提交
137
| set | LightWeightSet<T> | Yes| **LightWeightSet** instance whose elements are to be added to the current container.|
W
wusongqing 已提交
138

G
Gloria 已提交
139 140 141 142 143 144 145 146
**Error codes**

For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).

| ID| Error Message|
| -------- | -------- |
| 10200011 | The addAll method cannot be bound. |

W
wusongqing 已提交
147 148
**Example**

W
wusongqing 已提交
149
```ts
W
wusongqing 已提交
150
let lightWeightSet = new LightWeightSet();
G
Gloria 已提交
151 152
lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow");
W
wusongqing 已提交
153
let set = new LightWeightSet();
G
Gloria 已提交
154
set.add("gull");
W
wusongqing 已提交
155 156 157 158 159 160 161 162
let result = lightWeightSet.addAll(set);
```


### hasAll

hasAll(set: LightWeightSet<T>): boolean

W
wusongqing 已提交
163 164 165
Checks whether this container contains all elements of the specified **LightWeightSet** instance.

**System capability**: SystemCapability.Utils.Lang
W
wusongqing 已提交
166 167 168 169 170 171 172 173 174 175 176

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| set | LightWeightSet<T> | Yes| **LightWeightSet** instance to be used for comparison.|

**Return value**

| Type| Description|
| -------- | -------- |
W
wusongqing 已提交
177
| boolean | Returns **true** if all the elements in the specified **LightWeightSet** instance are contained; returns **false** otherwise.|
W
wusongqing 已提交
178

G
Gloria 已提交
179 180 181 182 183 184 185 186
**Error codes**

For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).

| ID| Error Message|
| -------- | -------- |
| 10200011 | The hasAll method cannot be bound. |

W
wusongqing 已提交
187 188
**Example**

W
wusongqing 已提交
189
```ts
W
wusongqing 已提交
190
let lightWeightSet = new LightWeightSet();
G
Gloria 已提交
191 192
lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow");
W
wusongqing 已提交
193
let set = new LightWeightSet();
G
Gloria 已提交
194
set.add("sparrow");
W
wusongqing 已提交
195 196 197 198 199 200 201 202 203 204
let result = lightWeightSet.hasAll(set);
```


### has

has(key: T): boolean

Checks whether this container has the specified key.

W
wusongqing 已提交
205 206
**System capability**: SystemCapability.Utils.Lang

W
wusongqing 已提交
207 208 209 210
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
W
wusongqing 已提交
211
| key| T | Yes| Target key.|
W
wusongqing 已提交
212 213 214 215 216 217 218

**Return value**

| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the specified key is contained; returns **false** otherwise.|

G
Gloria 已提交
219 220 221 222 223 224 225 226
**Error codes**

For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).

| ID| Error Message|
| -------- | -------- |
| 10200011 | The has method cannot be bound. |

W
wusongqing 已提交
227 228
**Example**

W
wusongqing 已提交
229
```ts
W
wusongqing 已提交
230 231 232
let lightWeightSet = new LightWeightSet();
let result = lightWeightSet.has(123);
lightWeightSet.add(123);
W
wusongqing 已提交
233
result = lightWeightSet.has(123);
W
wusongqing 已提交
234 235 236 237 238 239 240 241 242
```


### equal

equal(obj: Object): boolean

Checks whether this container contains objects of the same type as the specified **obj**.

W
wusongqing 已提交
243 244
**System capability**: SystemCapability.Utils.Lang

W
wusongqing 已提交
245 246 247 248 249 250 251 252 253 254 255 256
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| obj | Object | Yes| Object to be used for comparison.|

**Return value**

| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the container contains objects of the same type as the specified **obj**; returns **false** otherwise.|

G
Gloria 已提交
257 258 259 260 261 262 263 264
**Error codes**

For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).

| ID| Error Message|
| -------- | -------- |
| 10200011 | The equal method cannot be bound. |

W
wusongqing 已提交
265 266
**Example**

W
wusongqing 已提交
267
```ts
W
wusongqing 已提交
268
let lightWeightSet = new LightWeightSet();
G
Gloria 已提交
269 270 271
lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow");
let obj = ["squirrel", "sparrow"];
W
wusongqing 已提交
272 273 274 275 276 277 278 279 280 281
let result = lightWeightSet.equal(obj);
```


### increaseCapacityTo

increaseCapacityTo(minimumCapacity: number): void

Increases the capacity of this container.

W
wusongqing 已提交
282 283
**System capability**: SystemCapability.Utils.Lang

W
wusongqing 已提交
284 285 286 287
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
W
wusongqing 已提交
288
| minimumCapacity | number | Yes| Minimum number of elements to accommodate in the container.|
W
wusongqing 已提交
289

G
Gloria 已提交
290 291 292 293 294 295 296
**Error codes**

For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).

| ID| Error Message|
| -------- | -------- |
| 10200011 | The increaseCapacityTo method cannot be bound. |
G
Gloria 已提交
297
| 10200001 | The parameter value is out of range. |
G
Gloria 已提交
298

W
wusongqing 已提交
299 300
**Example**

W
wusongqing 已提交
301
```ts
W
wusongqing 已提交
302 303 304 305 306 307 308 309 310
let lightWeightSet = new LightWeightSet();
lightWeightSet.increaseCapacityTo(10);
```


### getIndexOf

getIndexOf(key: T): number

W
wusongqing 已提交
311 312 313
Obtains the position index of the element with the specified key in this container.

**System capability**: SystemCapability.Utils.Lang
W
wusongqing 已提交
314 315 316 317 318

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
W
wusongqing 已提交
319
| key| T | Yes| Key of the target element.|
W
wusongqing 已提交
320 321 322 323 324

**Return value**

| Type| Description|
| -------- | -------- |
W
wusongqing 已提交
325
| number | Position index of the element.|
W
wusongqing 已提交
326

G
Gloria 已提交
327 328 329 330 331 332 333 334
**Error codes**

For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).

| ID| Error Message|
| -------- | -------- |
| 10200011 | The getIndexOf method cannot be bound. |

W
wusongqing 已提交
335 336
**Example**

W
wusongqing 已提交
337
```ts
W
wusongqing 已提交
338
let lightWeightSet = new LightWeightSet();
G
Gloria 已提交
339 340 341
lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow");
let result = lightWeightSet.getIndexOf("sparrow");
W
wusongqing 已提交
342 343 344 345 346 347 348
```


### remove

remove(key: T): T

W
wusongqing 已提交
349 350 351
Removes an element of the specified key from this container.

**System capability**: SystemCapability.Utils.Lang
W
wusongqing 已提交
352 353 354 355 356

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
W
wusongqing 已提交
357
| key| T | Yes| Key of the target element.|
W
wusongqing 已提交
358 359 360 361 362

**Return value**

| Type| Description|
| -------- | -------- |
W
wusongqing 已提交
363
| T | Value of the element removed.|
W
wusongqing 已提交
364

G
Gloria 已提交
365 366 367 368 369 370 371 372
**Error codes**

For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).

| ID| Error Message|
| -------- | -------- |
| 10200011 | The remove method cannot be bound. |

W
wusongqing 已提交
373 374
**Example**

W
wusongqing 已提交
375
```ts
W
wusongqing 已提交
376
let lightWeightSet = new LightWeightSet();
G
Gloria 已提交
377 378 379
lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow");
let result = lightWeightSet.remove("sparrow");
W
wusongqing 已提交
380 381 382 383 384 385 386
```


### removeAt

removeAt(index: number): boolean

W
wusongqing 已提交
387 388 389
Removes the element at the specified position from this container.

**System capability**: SystemCapability.Utils.Lang
W
wusongqing 已提交
390 391 392 393 394

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
W
wusongqing 已提交
395
| index | number | Yes| Position index of the element.|
W
wusongqing 已提交
396 397 398 399 400

**Return value**

| Type| Description|
| -------- | -------- |
W
wusongqing 已提交
401
| boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.|
W
wusongqing 已提交
402

G
Gloria 已提交
403 404 405 406 407 408 409 410
**Error codes**

For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).

| ID| Error Message|
| -------- | -------- |
| 10200011 | The removeAt method cannot be bound. |

W
wusongqing 已提交
411 412
**Example**

W
wusongqing 已提交
413
```ts
W
wusongqing 已提交
414
let lightWeightSet = new LightWeightSet();
G
Gloria 已提交
415 416
lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow");
W
wusongqing 已提交
417 418 419 420 421 422 423 424
let result = lightWeightSet.removeAt(1);
```


### getValueAt

getValueAt(index: number): T

W
wusongqing 已提交
425 426 427
Obtains the value of the element at the specified position in this container.

**System capability**: SystemCapability.Utils.Lang
W
wusongqing 已提交
428 429 430 431 432

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
W
wusongqing 已提交
433
| index | number | Yes| Position index of the element.|
W
wusongqing 已提交
434 435 436 437 438 439 440

**Return value**

| Type| Description|
| -------- | -------- |
| T | Value obtained.|

G
Gloria 已提交
441 442 443 444 445 446 447 448
**Error codes**

For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).

| ID| Error Message|
| -------- | -------- |
| 10200011 | The getValueAt method cannot be bound. |

W
wusongqing 已提交
449 450
**Parameters**

W
wusongqing 已提交
451
```ts
W
wusongqing 已提交
452
let lightWeightSet = new LightWeightSet();
G
Gloria 已提交
453 454
lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow");
W
wusongqing 已提交
455 456 457 458 459 460 461 462 463 464
let result = lightWeightSet.getValueAt(1);
```


### clear

clear(): void

Clears this container and sets its length to **0**.

W
wusongqing 已提交
465 466
**System capability**: SystemCapability.Utils.Lang

G
Gloria 已提交
467 468 469 470 471 472 473 474
**Error codes**

For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).

| ID| Error Message|
| -------- | -------- |
| 10200011 | The clear method cannot be bound. |

W
wusongqing 已提交
475 476
**Example**

W
wusongqing 已提交
477
```ts
W
wusongqing 已提交
478
let lightWeightSet = new LightWeightSet();
G
Gloria 已提交
479 480
lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow");
W
wusongqing 已提交
481 482 483 484 485 486 487 488
lightWeightSet.clear();
```


### toString

toString(): String

W
wusongqing 已提交
489 490 491
Obtains a string that contains all elements in this container.

**System capability**: SystemCapability.Utils.Lang
W
wusongqing 已提交
492 493 494 495 496 497 498

**Return value**

| Type| Description|
| -------- | -------- |
| String | String obtained.|

G
Gloria 已提交
499 500 501 502 503 504 505 506
**Error codes**

For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).

| ID| Error Message|
| -------- | -------- |
| 10200011 | The toString method cannot be bound. |

W
wusongqing 已提交
507 508
**Example**

W
wusongqing 已提交
509
```ts
W
wusongqing 已提交
510
let lightWeightSet = new LightWeightSet();
G
Gloria 已提交
511 512
lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow");
W
wusongqing 已提交
513 514 515 516 517 518 519 520 521 522
let result = lightWeightSet.toString();
```


### toArray

toArray(): Array<T>

Obtains an array that contains all objects in this container.

W
wusongqing 已提交
523 524
**System capability**: SystemCapability.Utils.Lang

W
wusongqing 已提交
525 526 527 528 529 530
**Return value**

| Type| Description|
| -------- | -------- |
| Array<T> | Array obtained.|

G
Gloria 已提交
531 532 533 534 535 536 537 538
**Error codes**

For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).

| ID| Error Message|
| -------- | -------- |
| 10200011 | The toArray method cannot be bound. |

W
wusongqing 已提交
539 540
**Example**

W
wusongqing 已提交
541
```ts
W
wusongqing 已提交
542
let lightWeightSet = new LightWeightSet();
G
Gloria 已提交
543 544
lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow");
W
wusongqing 已提交
545 546 547 548 549 550 551 552 553 554
let result = lightWeightSet.toArray();
```


### values

values(): IterableIterator<T>

Obtains an iterator that contains all the values in this container.

W
wusongqing 已提交
555 556
**System capability**: SystemCapability.Utils.Lang

W
wusongqing 已提交
557 558 559 560 561 562
**Return value**

| Type| Description|
| -------- | -------- |
| IterableIterator<T> | Iterator obtained.|

G
Gloria 已提交
563 564 565 566 567 568 569 570
**Error codes**

For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).

| ID| Error Message|
| -------- | -------- |
| 10200011 | The values method cannot be bound. |

W
wusongqing 已提交
571 572
**Example**

W
wusongqing 已提交
573
```ts
W
wusongqing 已提交
574
let lightWeightSet = new LightWeightSet();
G
Gloria 已提交
575 576
lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow");
W
wusongqing 已提交
577 578 579 580 581 582 583 584 585 586 587
let iter = lightWeightSet.values();
let index = 0;
while(index < lightWeightSet.length) {
  console.log(JSON.stringify(iter.next().value));
  index++;
}
```


### forEach

G
Gloria 已提交
588
forEach(callbackFn: (value?: T, key?: T, set?: LightWeightSet&lt;T&gt;) => void, thisArg?: Object): void
W
wusongqing 已提交
589

W
wusongqing 已提交
590 591 592
Uses a callback to traverse the elements in this container and obtain their position indexes.

**System capability**: SystemCapability.Utils.Lang
W
wusongqing 已提交
593 594 595 596 597

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
G
Gloria 已提交
598
| callbackFn | function | Yes| Callback invoked to traverse the elements in the container.|
W
wusongqing 已提交
599 600 601 602 603
| thisArg | Object | No| Value to use when the callback is invoked.|

callbackfn
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
W
wusongqing 已提交
604 605
| value | T | No| Value of the element that is currently traversed.|
| key| T | No| Key of the element that is currently traversed (same as **value**).|
W
wusongqing 已提交
606 607
| set | LightWeightSet&lt;T&gt; | No| Instance that invokes the **forEach** method.|

G
Gloria 已提交
608 609 610 611 612 613 614 615
**Error codes**

For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).

| ID| Error Message|
| -------- | -------- |
| 10200011 | The forEach method cannot be bound. |

W
wusongqing 已提交
616 617
**Example**

W
wusongqing 已提交
618
```ts
W
wusongqing 已提交
619
let lightWeightSet = new LightWeightSet();
G
Gloria 已提交
620 621
lightWeightSet.add("sparrow");
lightWeightSet.add("gull");
W
wusongqing 已提交
622
lightWeightSet.forEach((value, key) => {
W
wusongqing 已提交
623
  console.log("value:" + value, key);
W
wusongqing 已提交
624 625 626 627 628 629 630 631
});
```


### entries

entries(): IterableIterator<[T, T]>

W
wusongqing 已提交
632 633 634
Obtains an iterator that contains all the elements in this container.

**System capability**: SystemCapability.Utils.Lang
W
wusongqing 已提交
635 636 637 638 639 640 641

**Return value**

| Type| Description|
| -------- | -------- |
| IterableIterator<[T, T]> | Iterator obtained.|

G
Gloria 已提交
642 643 644 645 646 647 648 649
**Error codes**

For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).

| ID| Error Message|
| -------- | -------- |
| 10200011 | The entries method cannot be bound. |

W
wusongqing 已提交
650 651
**Example**

W
wusongqing 已提交
652
```ts
W
wusongqing 已提交
653
let lightWeightSet = new LightWeightSet();
G
Gloria 已提交
654 655
lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow");
W
wusongqing 已提交
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
let iter = lightWeightSet.entries();
let index = 0;
while(index < lightWeightSet.length) {
  console.log(JSON.stringify(iter.next().value));
  index++;
}
```


### [Symbol.iterator]

[Symbol.iterator]\(): IterableIterator&lt;T&gt;

Obtains an iterator, each item of which is a JavaScript object.

W
wusongqing 已提交
671 672
**System capability**: SystemCapability.Utils.Lang

W
wusongqing 已提交
673 674 675 676 677 678
**Return value**

| Type| Description|
| -------- | -------- |
| IterableIterator&lt;T&gt; | Iterator obtained.|

G
Gloria 已提交
679 680 681 682 683 684 685 686
**Error codes**

For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).

| ID| Error Message|
| -------- | -------- |
| 10200011 | The Symbol.iterator method cannot be bound. |

W
wusongqing 已提交
687 688
**Example**

W
wusongqing 已提交
689
```ts
W
wusongqing 已提交
690
let lightWeightSet = new LightWeightSet();
G
Gloria 已提交
691 692
lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow");
W
wusongqing 已提交
693 694 695

// Method 1:
for (let item of lightWeightSet) { 
W
wusongqing 已提交
696
  console.log("value:" + item);
W
wusongqing 已提交
697 698 699 700 701 702
}

// Method 2:
let iter = lightWeightSet[Symbol.iterator]();
let temp = iter.next().value;
while(temp != undefined) {
W
wusongqing 已提交
703
  console.log("value:" + temp);
W
wusongqing 已提交
704 705 706
  temp = iter.next().value;
}
```