Hi,
I have an array that contains 10 elements, each element contains " ".
How do I create a string of spaces, like this:
" "
in javascript or jQuery from the this array?
Thank you
Hi,
I have an array that contains 10 elements, each element contains " ".
How do I create a string of spaces, like this:
" "
in javascript or jQuery from the this array?
Thank you
You would use Array.join() for this, like this:
var myArray = [" "," "," "," "," "," "," "," "," "," "];
var myString = myArray.join(''); //mySting is a string of 10 spaces
You need to pass the '' to .join() because the default joiner is a comma.
You can use join for that. Example:
var x = ['a', 'b', 'c', 'd'];
var y = x.join('');
Easy, try it yourself in address box:
javascript:alert('“'+new Array(42).join(' ')+'”')
By the way, "in jquery" should be "using jquery"