Chris Nizzardini, Salt Lake City Utah, Web Developer Specializing in LAMP+Ajax Since 2006

My Blog

Here is my awesome blog. You can find information on programming, linux, documentation, tips for code and database optimization, my thoughts and rants, and whatever else I feel like sharing. Feel free to contribute to the blog by posting comments and asking questions.
JavaScript and Ajax

More JavaScript Array Methods (push and join)

I found some other badly needed javascript methods today. Push (similiar to PHPs array_push function) and Join, which converts a simple array into a string. The Join method is great if you want to pass a dumb string to a server side language using an HTTP GET or POST.

Push

/* this can be defined as a global variable and then accessed by many different functions */
var myArr = new Array();
myArr.push("another element");

This simply adds another element to the end of the array.

Join

var myArr = new Array();
myArr[0] = "element 1";
myArr[1] = "element 2";
myArr[2] = "element 3";
var myStr = myArr.join(', ');

Now you have converted an array into a comma seperated string.

Related posts:

  1. JavaScript forEach
  2. Doing Math in JavaScript umm…sucks
  3. form checkboxes in php array and storing variables in url string
  4. looping through form fields in javascript

Leave a Reply