#### A string trim function
String.prototype.trim = function(){return this.replace(/^\s+|\s+$/g, "");}; 

#### Append an array to another array
var array1 = [12 , "foo" , {name "Joe"} , -2458];  
var array2 = ["Doe" , 555 , 100];  
Array.prototype.push.apply(array1, array2);

#### Transform the arguments object into an array
var argArray = Array.prototype.slice.call(arguments);

#### Verify that a given argument is a number  
function isNumber(n){
    return !isNaN(parseFloat(n)) && isFinite(n);
}

#### Empty an array
var myArray = [12 , 222 , 1000 ];  
myArray.length = 0; // myArray will be equal to []

#### Don’t use delete to remove an item from array
var items = [12, 548 ,'a' , 2 , 5478 , 'foo' , 8852, , 'Doe' ,2154 , 119 ];   
items.length; // return 11   
items.splice(3,1) ;   
items.length; // return 10   

#### Truncate an array using length
var myArray = [12 , 222 , 1000 , 124 , 98 , 10 ];  
myArray.length = 4; // myArray will be equal to [12 , 222 , 1000 , 124]

#### Pass functions, not strings, to setTimeout() and setInterval()
setInterval(doSomethingPeriodically, 1000);  
setTimeout(doSomethingAfterFiveSeconds, 5000);

#### An HTML escaper function
function escapeHTML(text) {  
    var replacements= {"<": "&lt;", ">": "&gt;","&": "&amp;", "\"": "&quot;"};                      
    return text.replace(/[<>&"]/g, function(character) {  
        return replacements[character];  
    }); 
}