-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray1.html
More file actions
66 lines (53 loc) · 1.63 KB
/
Array1.html
File metadata and controls
66 lines (53 loc) · 1.63 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
<!--
Arrays
-------
>Array is collection of elements (values).
>storing group of values with same refname is called array.
>array allows similar type of values (homogeneous) as well
as different types of values, means one array can store group
numbers, strings, strings, booleans etc....
>we can arrays create in local scope or outer scope.
>arrays are belongs to reference/non-primitive dataype.
>in js, arrays are created dynamically, and arrays are created
in heap area.
>arrays maintance data in sequence order
adv:
> arrays are sumplifying coding when work with group
of values.
> easy transporting data
> also used for data maintance in applications
array creation:
Approach 1:
using array Literals []
Syn: let/var/const array = [];
let/var/const array = [val1,val2,val3,...];
Approach 2:
using new kw & constructor
Syn: var/let/const array = new Array();
var/let/const array = new Array(val1,val2,...);
accessing array:
array[index]
index is a slno of memory block, its start 0.
set value:
array[index]=value;
size of array:
array.length => predefined property, it returns
sizi of array
array.length=N; => it reset size of array
-->
<h3> demo on array literal</h3>
<script>
//array declaration
let a=[];
document.write(`size of arr ${a.length}<br>`);
document.write(`arr ${a}<br>`);
a[0]=10;//asign
a[1]=20;
a[2]=30;
document.write(`size of arr ${a.length}<br>`);
document.write(`arr ${a}<br>`);
//array init
let b=[5,6,7];
document.write(`size of arr ${b.length}<br>`);
document.write(`arr ${b}<br>`);
</script>