You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1.### Add a key-value pair in object conditionally
25
+
1.### Conditional Statement
26
+
27
+
28
+
29
+
**Plain conditional operation**
30
+
31
+
```javascript
32
+
constis_employee=true;
33
+
let company
34
+
if(is_employee){
35
+
company='Inventives.ai';
36
+
}
37
+
else{
38
+
company=null;
39
+
}
40
+
```
41
+
42
+
43
+
- We will use Ternary operator
44
+
45
+
```javascript
46
+
const is_employee=true;
47
+
let company = is_employee?company='Inventives.ai':company=null;
48
+
```
49
+
50
+
**[⬆ Back to Top](#table-of-contents)**
51
+
52
+
53
+
54
+
55
+
2. ### Add a key-value pair in object conditionally
21
56
22
57
**Plain conditional operation**
23
58
@@ -73,10 +108,8 @@ One liner clean code snippets in javascript/react with ES6 syntax
73
108
74
109
75
110
76
-
2. ### Deleting a particular key from object
77
-
111
+
3. ### Deleting a particular key from object
78
112
79
-
80
113
**Plain conditional operation**
81
114
82
115
```javascript
@@ -112,6 +145,36 @@ One liner clean code snippets in javascript/react with ES6 syntax
112
145
113
146
114
147
- More code snippets are being added
148
+
149
+
150
+
4. ### Filling array with dummy values
151
+
152
+
153
+
154
+
**Plain conditional operation**
155
+
156
+
```javascript
157
+
const arr_length=6;
158
+
for(let i=0;i<arr_length;i++){
159
+
dummyArr[i] {'written_by' : 'Krishna Kant'};
160
+
}
161
+
```
162
+
163
+
164
+
- We will use Array instance with Higher Order Function-->array.map()
165
+
166
+
```javascript
167
+
168
+
const arr_length=6;
169
+
let dummyArr = new Array(arr_length).fill(null).map(()=>({'written_by' : 'Krishna Kant'}));
170
+
```
171
+
172
+
**[⬆ Back to Top](#table-of-contents)**
173
+
174
+
175
+
176
+
177
+
115
178
## Disclaimer
116
179
117
180
The code snippets mentioned inthis repository are the summary of frequently used codes in Javascript and/or React withES6syntax. We cannot guarantee that only these snippets will actually make the code cleaner, smoother and optimised, nor should you focus on copying and pasting them all. The primary purpose is for you to get a sense of how some bulk codes might be replaced with one-liner ES6 conditional and operational statements!
0 commit comments