0

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?

3
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by Airshow
0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.