-
Notifications
You must be signed in to change notification settings - Fork 0
/
Note.txt
228 lines (219 loc) · 5.14 KB
/
Note.txt
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
Contents:
Introduction to Array
Array and Object JSON iteration
Array & Object Destructuring [] {key}
object.this Method
Create New Objects Using New Method
Objects:-
=>Js objects are data structures used to store and organize data.
=>Objects are variables too.
=>objects always declared in key-value pairs
=>Object is called real time entity (touch and feel)
=>But object contains many values & can be with different datatypes
var/let/const objectname =
{
key: value
}
Example:-
=> A car has prop like weight and color & methods like start and stop
=> All car has same method but prop differ from car to car
=> There are 2 ways to declare objects.
1. to declare objects using curly brackets {}
const person ={
name: "Rajini",
age: 45,
occupation: "actor"
}
=> to print the output in object we have 2 methods
**dot notation
console.log(person.name); // Rajini
console.log(person.age); //45
console.log(person.occupation); //actor
**square brackets
console.log(person["name"]);// Rajini
console.log(person["age"]);// 45
console.log(person["occupation"]);// actor
2. to declare objects using new methods (Object constructor using the new keyword)
const person = new Object();
person.name = "rajini";
person.age = 45;
person.occupation = "actor";
==>Modifying the Object
const person = {
name: "rajini",
age: 45
}
=> there are two methods to modify object
1.dot notation
person.name= "kamal"
console.log(person);
//{name:"kamal",age:45}
2.square brackets
person["age"]=60;
console.log(person);
//{name:"kamal",age:60}
==>Adding a new property
const person = {
name:"kamal",
age:60
}
person.occupation= "actor"
console.log(person);
//{name:"kamal",age:60,occupation:"actor"}
==>Removing Obj property
const person = {
name:"kamal",
age:60,
city: "chennai"
}
delete person.city // it will delete the city prop in obj
console.log(person);
//{name:"kamal",age:60}
**------------------------------------------------------------**
==> Array and Object JSON iteration
JSON:-
=>(Javascript Object Notation) is a lightweight data interchange format.
=>It uses key value pairs
=>similar to object
=>the synatx consists of 2 types {} is for object json , [] is for array json
====>JSON Object
const person={
name: "kamal",
age:60
}
===>JSON Array
const fruits = ["apple","banana","orange"]
==>Parse JSON : to convert a json string into a javascript object.
synatx: JSON.parse()
example:
const a = '{"name":"kamal","age":60}';
console.log(a);
var b = JSON.parse(a);
console.log(b);
==>JSON.stringify : to convert a javascript object into a json string.
const c = {
name: "kamal",
age: 60
}
console.log(c)
const d = JSON.stringify(c);
console.log(d)
==>Nested JSON object
var person = {
"name":"kamal",
"age" :60,
"occupation":"actor",
"address": {
"city" : "chennai",
"pincode" : 60001
}
}
console.log(person)
console.log(person.address.city)
==>Nested JSON array
var person = [
{
"name":"kamal",
"age":60
},
{
"name":"rajini",
"age":55
}
]
console.log(person)
console.log(person[1].age)//55
**--------------------------------------**
Array & Object Destructuring
==>Array Destructuring
const arr = [1,2,3];
const[x,z,wwww,d=4]= arr;
console.log(x);
console.log(z);
console.log(wwww);
console.log(d);
console.log(arr);
==> Object Destructuring
const obj = {
name: "kamal",
age:60,
address:{
city: "chennai",
pin: 60001
}
}
//const{key}=objectname
const {name,age}= obj;
console.log(name);
console.log(age);
without Destructuring
//console.log(obj.address.city)
****-----------------------------------------***
Use Strict in Js
without strict mode
fullname = "kamal"
console.log(fullname)
with strict mode
'use strict';
fullname = "kamal"
console.log(fullname)
*************------------------------------**********
object.this Method
=>this keyword refers to an object
=> Which object depends on how this is being invoked(used or called)
1. Using "this" keyword alone, refers to global object
2. In regular function , refers to global object
3. In a function in strict mode , "this" is undefined.
4. In a method, "this" refers to the owner object.
Example:-
1. Using "this" keyword alone, refers to global object
console.log(this);
2.In regular function , refers to global object
const a = function(){
console.log("hello world");
console.log(this)
}
a();
3. In a function in strict mode , "this" is undefined.
'use strict';
const a = function(){
console.log("strict mode");
console.log(this)
}
a();
4. In a method, "this" refers to the owner object.
const person = {
names : "kamal",
age: 60,
occupation: "actor"
detail: function(){
console.log(`I love ❤ ${this.names}`)
}
}
console.log(person.detail());
***------------------------------------------------------****
Javascript Object methods
1.Object.assign();
2.Object.create();
3.Object.entries();
4.Object.freeze();
5.Object.keys();
6.Object.values();
7.Object.seal();
*************---------------------------------------------**********
title caps steps:
tolowercase
split
for loop
charAt(0)
touppercase
slice
join
palindrome steps
slice
tostring
split
reverse
join
for()
push