Monday, November 21, 2011

push in jQuery appends a record to an array

You may not be able to append items to an array the way you can with a List<T> in C#, but jQuery, as it turns out, does not have such a shortcoming. Look:

var fruits = "apple,orange,banana";

fruitbasket = new Array();

fruitbasket = fruits.split(',');

fruitbasket.push("grape");

alert(fruitbasket[0]);

alert(fruitbasket[1]);

alert(fruitbasket[2]);

alert(fruitbasket[3]);

 
 

I was misguided and made some false assumptions when I crafted this. :)

No comments:

Post a Comment