-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlearn-array.js
More file actions
35 lines (31 loc) · 759 Bytes
/
learn-array.js
File metadata and controls
35 lines (31 loc) · 759 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
31
32
33
34
35
//Array - collection of data
/*let arr = ["1", "2", "3", "4"];
console.log(arr);
console.log(arr[0]);
console.log(arr.length);
for (let i = 0; i < arr.length; i++) {
console.log("value is:", arr[i]);
} */
let arr = ["David", 28, false];
console.log(arr);
//occurence of "a"
/* let str = "I am in bangalore";
let count = 0;
let arr = str.split("");
for (let i = 0; i < arr.length; i++) {
if (arr[i] === "a") {
count++;
}
}
console.log("Count of a:", count); */
//largest word in the string
/* let str = "I am in bangalore to attend a magical-musium";
let arr = str.split(" ");
console.log(arr);
let largest = " ";
for (let i = 0; i < arr.length; i++) {
if (arr[i].length > largest.length) {
largest = arr[i];
}
}
console.log(largest); */