Javascript: Global object window


– test –



  1. window.onresize = property contains an EventHandler triggered when a resize event is received.

Example:

window.onresize = function() {

alert('resize test');

}

2. window.onload = property contains an EventHandler when load event of a WindowXMLHttpRequest<img> element is received.

Example:

window.onload = function() {

alert('do something');

};

Javascript – Array Methods

Methods:

  1. The splice() method: Adds/Removes Elements in Array.

Example:

var months = ['Jan', 'March', 'April', 'June'];
months.splice(1, 0, 'Feb');
// inserts at 1st index position
console.log(months);
// expected output: Array ['Jan', 'Feb', 'March', 'April', 'June']


months.splice(4, 1, 'May');
// replaces 1 element at 4th index
console.log(months);
// expected output: Array ['Jan', 'Feb', 'March', 'April', 'May']

2. The slice() method: Makes the copy of Array into new object with start to end index.

Example:

var animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];

console.log(animals.slice(2));
// expected output: Array ["camel", "duck", "elephant"]

console.log(animals.slice(2, 4));
// expected output: Array ["camel", "duck"]