forked from halitkalayci/js-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdestructuring.js
39 lines (34 loc) · 1.05 KB
/
destructuring.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { cevaplariniz } from "./restAndSpread.js";
//require();
console.log("------------");
console.log(cevaplariniz);
//const first = cevaplariniz[0];
//const second = cevaplariniz[1];
const [first, second, ...others] = cevaplariniz; // array destructuring
console.log(first, second, others);
// 10, 20, [30, 40, 50]
//
const [icAnadolu, marmara, ege, akdeniz, [icAnadoluSehirleri, marmaraSehirleri, ...digerSehirler]] = [
{ name: "İç Anadolu", population: 1000000 },
{ name: "Marmara", population: 2000000 },
{ name: "Ege", population: 3000000 },
{ name: "Akdeniz", population: 4000000 },
[
["Ankara", "Konya"],
["İstanbul", "Bursa"],
["İzmir", "Manisa"],
["Antalya", "Mersin"],
],
];
console.log(icAnadolu, marmara, ege, akdeniz);
console.log(...icAnadoluSehirleri);
console.log(...marmaraSehirleri);
//const [egeSehirleri, akdenizSehirleri] = ...digerSehirler;
console.log(...digerSehirler.flat(2));
// Ankara, Konya
/* [
["Ankara", "Konya"],
["İstanbul", "Bursa"],
["İzmir", "Manisa"],
["Antalya", "Mersin"],
] */