1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16const objects: { a: number; b: string }[] = [
17  { a: 10, b: 'q' },
18  { a: 20, b: 'w' },
19  { a: 30, b: 'e' },
20];
21for (const { a, b } of objects) {
22  console.log(a, b);
23}
24
25const arrays = [
26  [1, 2],
27  [3, 4],
28  [5, 6],
29];
30for (const [q, w] of arrays) {
31  console.log(q, w);
32}
33
34let a: number, b: string;
35for ({ a, b } of objects) {
36  console.log(a, b);
37}
38
39let x: number, y: number;
40for ([x, y] of arrays) {
41  console.log(x, y);
42}
43
44const people = [
45  {
46    name: 'Mike Smith',
47    family: { mother: 'Jane Smith', father: 'Harry Smith' },
48  },
49  {
50    name: 'Tom Jones',
51    family: { mother: 'Norah Jones', father: 'Richard Jones' },
52  },
53];
54let n: string, f: string;
55for ({
56  name: n,
57  family: { father: f },
58} of people) {
59  console.log(`Name: ${n}, Father: ${f}`);
60}