Wednesday, January 19, 2011

Javascript:Remove the last character in a string

var str = 'Dear Raj!';
var newStr = str.substring(0, str.length-1);
//alert(newStr); 
but the simplest is
str.slice(0,-1) 

Monday, January 10, 2011

JQuery-Remove Duplicates from an Array

function uniqueArray(myarray)// to remove the duplicates from an Array
{
//var vals = this;
var uniques = [];
for(var i=myarray.length;i--;){
var val = myarray[i];
if($.inArray( val, uniques )===-1){
uniques.unshift(val);
}
}

return uniques;
}

Thursday, January 6, 2011

JQuery-Create Dropdown from Array

$.each(myArray,function(i,j){
$("<option value=" +i+ ">" +j+ "</option>").appendTo('#ddname');
});