-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01_array.js
More file actions
42 lines (29 loc) · 1.21 KB
/
01_array.js
File metadata and controls
42 lines (29 loc) · 1.21 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
// array
// shallow Copy object share the same referance
// Deep Copy object do not share same referance they share the copy
const myArr = [ 'Rohit', 1, 2, 3, 4, 5]
// const myHero = ['shaktiman', 'Rohitman']
// const myArr2 = new Array(1 ,2, 3, 4, 5)
// console.log(myArr[0]);
// Array methods
// myArr.push("yadav") // push is used to add the value in array
// myArr.push(9) // push is used to add the value in array
// myArr.pop() // pop is used to remove the last value
// myArr.unshift(8) // Is used to add any element in start
// myArr.shift() // remove the starting element
// myArr.shift()
// console.log(myArr.includes(5)); // check wheather 5 is here or not
// console.log(myArr.indexOf('Rohit'));
// const newArr = myArr.join() // join is used to covert array to string
// console.log(myArr);
// console.log(newArr);
// Slice, Splice
console.log("A" , myArr);
const myn1 = myArr.slice(1,3) // 1 and 2 no is include but not 3 no is not include in slice
console.log(myn1);
console.log("B", myArr);
const myn2 = myArr.splice(1,3)
console.log("C", myArr);
console.log(myn2);
// slice do not manuplate the original array
//splice manuplate or change the original array