-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoops.js
More file actions
135 lines (100 loc) · 3.09 KB
/
Copy pathLoops.js
File metadata and controls
135 lines (100 loc) · 3.09 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Loops
/* For */
/*
for([başlangıçAtaması]; [koşulifadesi]; [döngüSonundaÇalışacakİfade]) {
yapılacak işlem
}
10'a kadar yazdırma
for(let index = 0; index < 10; index++){
console.log('İndex : ', index)
}
*/
let users = ["Lorem", "İpsum", "Dolor", ""]
const userListDOM = document.querySelector('#userList')
for(index = 0; index < users.length; index++){
const liDom = document.createElement('li')
liDom.innerHTML= users[index]
userListDOM.appendChild(liDom)
}
/* Break & Contunie */
const LOREM_LIST = [
`lorem`, `ipsum`, `dolor`,`amet`, `consectetur`, `adipisicing`, `elit`, ``
]
let counter = 0
/* for(; counter < 10; counter++){
console.log('break', counter)
if(counter === 5) {break} // Buraya kadar gel anlamına geliyor.
} */
/* for(; counter < 10; counter++){
if(counter === 5) {continue} //
console.log('continue', counter)
} */
const UL_DOM = document.querySelector("#userList")
/* for(i=0; i < LOREM_LIST.length; i++){
if(LOREM_LIST[i] == "dolor") {break}
let liDOM = document.createElement('li')
liDOM.innerHTML = LOREM_LIST[i]
UL_DOM.append(liDOM)
} */
for(i=0; i < LOREM_LIST.length; i++){
if(LOREM_LIST[i] == "continue") {continue}
let liDOM = document.createElement('li')
liDOM.innerHTML = LOREM_LIST[i]
UL_DOM.append(liDOM)
}
/* While */
/*
while(koşul){
Yapılacak işlem;
}
*/
let x = 0
while(x < 10){
console.log('while', x)
x ++
}
/* let userName;
while(!userName) // Yok olduğu sürece çalış
{
userName = prompt("Kullanıcı Aadınızı Giriniz :")
console.log(userName)
} */
/* forEach */
/*
arr.forEach(function(value, index, array) {
index ve array kullanmak opsiyoneldir
}
*/
const PRODUCTS = ["Laptop", "Phone", "Speaker", "Desktop PC", "Server", "Mouse", "Keyboard"]
PRODUCTS.forEach((product, index, array) => array[index] = product + " 111")
console.log(PRODUCTS)
const userListDOm = document.querySelector('#userList')
PRODUCTS.forEach(item =>{
const liDom = document.createElement('li')
liDom.innerHTML= item
userListDOm.appendChild(liDom)
}
)
/* Array filter */
// 5harften fazla olanalar (6)
const PRODUCTS_2 = ["MİC", "CABLE", "SPEAKER", "DESKTOP PC", "SERVER", "MOUSE", "KEYBOARD"]
const New_Products = PRODUCTS_2.filter(new_item => new_item.length > 6)
console.log('New Products', New_Products)
// Aktif olanlar
const USERS = [
{fullname: "Anonim 1", isActive: false},
{fullname: "Anonim 2", isActive: true},
{fullname: "Anonim 3", isActive: false},
{fullname: "Anonim 4", isActive: true},
]
const Active_users = USERS.filter(new_users => new_users.isActive === true) // direkt olarak true istiyorsak "new_users.isActive yazmamız yeterli. Sadece false için kullanıcaksak mantıklı."
console.log('Active Users', Active_users)
/* Map */
const USERS_2 = ["Ayşe", "Mehmet", "Tuğçe", "Aksel"]
const NEW_USERS = USERS_2.map(user => user.toLowerCase())
console.log('Lower Case', NEW_USERS)
/* const USERS_OBJ = USERS.map(i =>
{
return{userName: item, shortName: `${item[0]}`, newName: `${item[0]}.toUpperCase()`}
}
) */