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

W
wusongqing 已提交
3
> **NOTE**
W
wusongqing 已提交
4
> 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 已提交
5

W
wusongqing 已提交
6 7 8 9 10 11 12 13 14
**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 已提交
15

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

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

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

## LightWeightSet

### Attributes

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

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


### constructor

constructor()

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

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

G
Gloria 已提交
44 45
**Error codes**

46
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
G
Gloria 已提交
47 48 49 50 51

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

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

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


### isEmpty

isEmpty(): boolean

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

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

**Return value**

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

G
Gloria 已提交
73 74
**Error codes**

75
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
G
Gloria 已提交
76 77 78 79 80

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

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

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

### add

add(obj: T): boolean

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

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

**Parameters**

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

**Return value**

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

G
Gloria 已提交
108 109
**Error codes**

110
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
G
Gloria 已提交
111 112 113 114 115

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

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

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


### addAll

addAll(set: LightWeightSet<T>): boolean

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

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

**Parameters**

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

G
Gloria 已提交
138 139
**Error codes**

140
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
G
Gloria 已提交
141 142 143 144 145

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

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

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


### hasAll

hasAll(set: LightWeightSet<T>): boolean

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

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

**Parameters**

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

**Return value**

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

G
Gloria 已提交
178 179
**Error codes**

180
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
G
Gloria 已提交
181 182 183 184 185

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

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

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


### has

has(key: T): boolean

Checks whether this container has the specified key.

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

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

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

**Return value**

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

G
Gloria 已提交
218 219
**Error codes**

220
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
G
Gloria 已提交
221 222 223 224 225

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

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

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


### equal

equal(obj: Object): boolean

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

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

W
wusongqing 已提交
244 245 246 247
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
248
| obj | Object | Yes| **LightWeightSet** instance to be used for comparison.|
W
wusongqing 已提交
249 250 251 252 253 254 255

**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 已提交
256 257
**Error codes**

258
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
G
Gloria 已提交
259 260 261 262 263

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

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

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


### increaseCapacityTo

increaseCapacityTo(minimumCapacity: number): void

Increases the capacity of this container.

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

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

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

G
Gloria 已提交
289 290
**Error codes**

291
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
G
Gloria 已提交
292 293 294 295

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

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

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


### getIndexOf

getIndexOf(key: T): number

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

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

**Parameters**

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

**Return value**

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

G
Gloria 已提交
326 327
**Error codes**

328
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
G
Gloria 已提交
329 330 331 332 333

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

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

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


### remove

remove(key: T): T

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

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

**Parameters**

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

**Return value**

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

G
Gloria 已提交
364 365
**Error codes**

366
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
G
Gloria 已提交
367 368 369 370 371

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

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

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


### removeAt

removeAt(index: number): boolean

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

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

**Parameters**

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

**Return value**

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

G
Gloria 已提交
402 403
**Error codes**

404
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
G
Gloria 已提交
405 406 407 408 409

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

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

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


### getValueAt

getValueAt(index: number): T

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

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

**Parameters**

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

**Return value**

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

G
Gloria 已提交
440 441
**Error codes**

442
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
G
Gloria 已提交
443 444 445 446 447

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

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

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


### clear

clear(): void

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

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

G
Gloria 已提交
466 467
**Error codes**

468
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
G
Gloria 已提交
469 470 471 472 473

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

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

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


### toString

toString(): String

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

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

**Return value**

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

**Example**

W
wusongqing 已提交
500
```ts
W
wusongqing 已提交
501
let lightWeightSet = new LightWeightSet();
G
Gloria 已提交
502 503
lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow");
W
wusongqing 已提交
504 505 506 507 508 509 510 511 512 513
let result = lightWeightSet.toString();
```


### toArray

toArray(): Array<T>

Obtains an array that contains all objects in this container.

W
wusongqing 已提交
514 515
**System capability**: SystemCapability.Utils.Lang

W
wusongqing 已提交
516 517 518 519 520 521
**Return value**

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

G
Gloria 已提交
522 523
**Error codes**

524
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
G
Gloria 已提交
525 526 527 528 529

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

W
wusongqing 已提交
530 531
**Example**

W
wusongqing 已提交
532
```ts
W
wusongqing 已提交
533
let lightWeightSet = new LightWeightSet();
G
Gloria 已提交
534 535
lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow");
W
wusongqing 已提交
536 537 538 539 540 541 542 543 544 545
let result = lightWeightSet.toArray();
```


### values

values(): IterableIterator<T>

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

W
wusongqing 已提交
546 547
**System capability**: SystemCapability.Utils.Lang

W
wusongqing 已提交
548 549 550 551 552 553
**Return value**

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

G
Gloria 已提交
554 555
**Error codes**

556
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
G
Gloria 已提交
557 558 559 560 561

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

W
wusongqing 已提交
562 563
**Example**

W
wusongqing 已提交
564
```ts
W
wusongqing 已提交
565
let lightWeightSet = new LightWeightSet();
G
Gloria 已提交
566 567
lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow");
W
wusongqing 已提交
568 569 570 571 572 573 574 575 576 577 578
let iter = lightWeightSet.values();
let index = 0;
while(index < lightWeightSet.length) {
  console.log(JSON.stringify(iter.next().value));
  index++;
}
```


### forEach

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

W
wusongqing 已提交
581 582 583
Uses a callback to traverse the elements in this container and obtain their position indexes.

**System capability**: SystemCapability.Utils.Lang
W
wusongqing 已提交
584 585 586 587 588

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
589
| callbackFn | function | Yes| Callback invoked to traverse the elements in the container.|
W
wusongqing 已提交
590 591 592 593 594
| thisArg | Object | No| Value to use when the callback is invoked.|

callbackfn
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
W
wusongqing 已提交
595 596
| 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 已提交
597 598
| set | LightWeightSet&lt;T&gt; | No| Instance that invokes the **forEach** method.|

G
Gloria 已提交
599 600
**Error codes**

601
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
G
Gloria 已提交
602 603 604 605 606

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

W
wusongqing 已提交
607 608
**Example**

W
wusongqing 已提交
609
```ts
W
wusongqing 已提交
610
let lightWeightSet = new LightWeightSet();
G
Gloria 已提交
611 612
lightWeightSet.add("sparrow");
lightWeightSet.add("gull");
W
wusongqing 已提交
613
lightWeightSet.forEach((value, key) => {
G
Gloria 已提交
614
    console.log("value:" + value, "key:" + key);
W
wusongqing 已提交
615 616 617 618 619 620 621 622
});
```


### entries

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

W
wusongqing 已提交
623 624 625
Obtains an iterator that contains all the elements in this container.

**System capability**: SystemCapability.Utils.Lang
W
wusongqing 已提交
626 627 628 629 630 631 632

**Return value**

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

G
Gloria 已提交
633 634
**Error codes**

635
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
G
Gloria 已提交
636 637 638 639 640

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

W
wusongqing 已提交
641 642
**Example**

W
wusongqing 已提交
643
```ts
W
wusongqing 已提交
644
let lightWeightSet = new LightWeightSet();
G
Gloria 已提交
645 646
lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow");
W
wusongqing 已提交
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661
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 已提交
662 663
**System capability**: SystemCapability.Utils.Lang

W
wusongqing 已提交
664 665 666 667 668 669
**Return value**

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

G
Gloria 已提交
670 671
**Error codes**

672
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
G
Gloria 已提交
673 674 675 676 677

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

W
wusongqing 已提交
678 679
**Example**

W
wusongqing 已提交
680
```ts
W
wusongqing 已提交
681
let lightWeightSet = new LightWeightSet();
G
Gloria 已提交
682 683
lightWeightSet.add("squirrel");
lightWeightSet.add("sparrow");
W
wusongqing 已提交
684 685 686

// Method 1:
for (let item of lightWeightSet) { 
W
wusongqing 已提交
687
  console.log("value:" + item);
W
wusongqing 已提交
688 689 690 691 692 693
}

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