-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.js
More file actions
101 lines (49 loc) · 1.48 KB
/
array.js
File metadata and controls
101 lines (49 loc) · 1.48 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Array = a variabe l1ke structure that can hold more than 1 value.
// ----------------array mathods
// fruit.push() to add "a value" in to array
// fruit.pop() to remove last element in a array
// fruit.unshift() to add a value fast element in a array
// --------------------------
// let b = array.unshift("hsks")
// console.log(b);
// let c = array.pop()
// console.log(c);
// console.log(array);
let array = ['apple','orange','grapes','pineapple']
// let index =array.indexOf("apple")
// console.log(index);
// for (i = 0; i<array.length; i++){
// console.log(array[i]);
// }
// for (let i = array.length -1 ;i >= 0 ; i--){
// console.log(array[i]);
// }
for (let i = array.length ;i >= 0 ; i--){
console.log(array.sort().reverse()[i]);
}
// ----------------short hand methid
// let array = ['apple','orange','grapes','pineapple']
// for(let a of array ){
// console.log(a);
// }
// -----------sort method
// let sort = array.sort();
// console.log(sort);
// ---------reverse method
// let reverse = array.reverse();
// console.log(reverse);
// let a = "how are u babe "
// function reverse_str(str){
// let reverse = ""
// for(a=str.length -1; a>=0 ; a--){
// reverse += str[a]
// }
// return reverse;
// }
// let b = "apple"
// let c = reverse_str(b)
// console.log(c);
// let array = ["apple","pineapple","bananna"]
// for(let i = array.length -1; i >= 0; i--){
// console.log(array.reverse()[i]);
// }