-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray1.js
More file actions
30 lines (27 loc) · 807 Bytes
/
array1.js
File metadata and controls
30 lines (27 loc) · 807 Bytes
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
const myarr=[0,1,2,3,4,5]
const myHeros=["shaktiman","batman"]
const myarr2=new Array(1,2,3,4)
console.log(myarr[0])
//array methods
myarr.push(6)
myarr.push(8)
myarr.pop() //removes last element of the array
console.log(myarr)
myarr.unshift(9) //adds an element at the beginning of the array ,it is not preferred because it changes the index of every element
console.log(myarr)
myarr.shift()
console.log(myarr)
console.log(myarr.includes(3))// this mehod tell whether the element is present or not
console.log(myarr.indexOf(98));
const newarr=myarr.join()
console.log(newarr);
console.log(myarr);
console.log(typeof newarr)
// slice,splice
console.log("A",myarr)
const myn1=myarr.slice(1,3)
console.log(myn1)
console.log("B",myarr)
const myn2=myarr.splice(1,3)
console.log("C",myarr)
console.log(myn2)