JavaScript Arrays | Basics | Events

JavaScript Arrays | Basics

An array is an ordered collection of homogeneous elemenets stored in the meory in contiguous locations. All the elements in a Javasritp array should be of the same type. Javascript does not support asociative arrys i.e., arrays containing keys and their rerspective values

To create an array, use
let arr=new Array();
To set a value for
arr[0] = "Gaurav";
arr[1]="Shirodkar";
To access an array value, use
arr[0];
Al;l the elements of the array are stroed in contiguous memory locations and their data type of a elements should be the same.

Suppose, I had an array called arr
let arr = [0,1,2,3,4,5];
If we want to erxtract a part of an array from 1 to 3, use
arr.slice(1,3);
To extract vfronm the end of the array,
use the '-' sign, for eg, the slice(-2,2)

To insert an eleemnt at tyhe of an array,
use arr.push(9);
The result will be :-
arr=[0,1,2,3,4,5,9];

To remove an element from the end of an array, use arr.pop();
The result will be :
arr=[0,1,2,3,4,5];
(Since 9 is removed, it will be removed from the array)

To split a string into differnet variables, use str.split(",");
Suppose, str = "1,2,3,4,5";
then str.split(","); will return as arr (1,2,3,4,5)


To join array elements into a single string, use arr.join(",");
Suppose arr=[1,2,3,4,5]; then arr.join(",") will be "1,2,3,4,5";

Event Object Properties

On pressing "i", the event got triggered and the event object got passed to the event listener which uses the keyCode property of the keypress event to get the ASCII code for that key and then using document.write() prints the ASCII Code on the screen

Comments

Popular posts from this blog

Parallel Database design, query processing

Laravel | PHP | Basics | Part 2

Apache Hadoop | Running MapReduce Jobs