var myArray = new Array(10);
var myArray = [];
--------------------------------------------------
Javascript Arrays Are Passed By Reference to functions !!!
var fruits = ["Banana", "Orange", "Apple", "Mango"];
document.write(fruits.sort());
>>> Apple,Banana,Mango,Orange
--------------------------------------------------
function sortNumber(a,b)
{
return a - b;
}
--------------------------------------------------
var n = ["10", "5", "40", "25", "100", "1"];
document.write(n.sort(sortNumber));
>>> 1,5,10,25,40,100
--------------------------------------------------
function compareNumbers ( a, b )
{
if ( a < b )
return -1;
if ( a > b )
return 1;
return 0; // a == b
}
var ages = [ 7, 105, 14 ];
ages.sort ( compareNumbers );
alert ( ages ); // displays "7,14,105"
--------------------------------------------------
var a = [30,2,1,9,15];
a.sort(function(a,b) { return a-b; });
--------------------------------------------------
locations.sort(
function(a, b) {
if (a.name < b.name) return -1;
if (a.name > b.name) return 1;
return 0;
}
);
--------------------------------------------------
var numbersarray=[-3, 5, 34, 19]
function greaterThanFive(element, index, array) {
return (element > 5)
}
var FiveplusArray=numbersarray.filter(greaterThanFive) //new array contains [34, 19]