Look at the code...

var css_code = new Array();

css_code[css_code.length + 1] = "<div style='height: "+square_height+"; width: "+square_width+"; "+square_rounded+" border: "+border_width+" "+border_type+" "+border_color+"; position: absolute;'></div>";

This is just a tiny snippet of a huge amount of code, but when I add a new item to the css_code array. An extra comma comes in when I output the array on the screen, why?

Joe,

I expect you are seeing a comma between each entry of the array.

Try outputting css_code.join('') to join the elements without commas.

You can also simplify the code slightly as follows:

var css_code = [];//shorthand for new Array()

css_code.push("<div style='height: "+square_height+"; width: "+square_width+"; "+square_rounded+" border: "+border_width+" "+border_type+" "+border_color+"; position: absolute;'></div>");//.push() adds an element to the end of the array.

Airshow

Airshow's solution is correct. The problem was css_code[css_code.length + 1] : if you have for example 2 elements in your array, css_code.length + 1 equals 3. But css_code[3] is the 4th element in your array, so you're leaving one open.

Yea thanks everyone I fixed everything!

Thanks Twiss, I should have said that but didn't have time earlier.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.