Arrays
Arrays are used to store multiple values in a single variable.
An array is a special variable which can hold more than one value at a time.
We can access the value of an array by using array index.
Array index will start from zero.
Creating an array;
syntax: var array_name=["item1","item2","item3" ........];
var array-name= new array("item1","item2",.....);
EX:
Code:
OUTPUT:
Accessing Array Elements by using Index number:
Code:
OUTPUT:
Pop():
Push:
Shifting :
Sorting:
Code:
EX: Popping:
OUTPUT
Code:
EX:Shifting:
OUTPUT:
EX:Sorting
Code:
OUTPUT:
After Clicking the button
Arrays are used to store multiple values in a single variable.
An array is a special variable which can hold more than one value at a time.
We can access the value of an array by using array index.
Array index will start from zero.
Creating an array;
syntax: var array_name=["item1","item2","item3" ........];
var array-name= new array("item1","item2",.....);
EX:
Code:
OUTPUT:
Accessing Array Elements by using Index number:
Code:
OUTPUT:
Pop():
- Popping an array means removing or deleting an element from array.
- Pop will remove the last inserted value from array.
- Syntax: array_name.pop();
Push:
- Pushing an array means inserting new elements into the array.
- Syntax:array_name("value1","value2");
Shifting :
- Shifting also works same like popping.
- This will remove th efirst element and shifts all other elements index to lower number.
- Syntax:array_name.Shift();
Sorting:
- It will sort the array elements into alphabetically.
- Syntax:array_name.sort();
Code:
EX: Popping:
OUTPUT
Code:
EX:Shifting:
OUTPUT:
EX:Sorting
Code:
OUTPUT:
After Clicking the button