-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharr.js
More file actions
59 lines (41 loc) · 1.12 KB
/
arr.js
File metadata and controls
59 lines (41 loc) · 1.12 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
//arrays in javascript
let arr=[];
console.log(arr);
//indexing is 0 based
let arrnew= [1,2,3,4.56,"i am array"];
console.log(arrnew);
// printing particular element in array
console.log("the element is" + arrnew[2] );
//changing element in array
arrnew[2]= "nothing";
console.log(arrnew);
// Arrays method
//1- push
console.log("array before pushing"+ arrnew);
arrnew.push("i am pushed :)");
console.log("array after pushing" + arrnew);
//practice code
// let brr=[1,4,3,,6,78,4,5,7,8];
// let flag = 0;
// for(let i =0;i<brr.length;i++){
// if(brr[i]%2==0){
// flag=1;
// }
// }
// if(flag==1){
// console.log(brr[i]+"Even");
// }else{
// console.log("odd");
// }
//2-Pop method-Removes the last element from the list
console.log("array before"+arrnew);
arrnew.pop();
console.log("array after" + arrnew);
//3- shift- Removes first element from the list
console.log("array before" + arrnew);
arrnew.shift();
console.log("array after" + arrnew);
//4- Unshift- Adds element to the start
console.log("array before" + arrnew);
arrnew.unshift("i am the new element");
console.log("array after" + arrnew);