0

String array :

var name=new String('Here','Is','Wasif');

I have tried this to print it : 

for(var i=0;i< name.length;i++)
        document.write(name[i]);
2
  • 1
    that isn't a string array. Commented Nov 18, 2013 at 0:21
  • 1
    new String('Here','Is','Wasif') -> new String('Here') -> "Here". The additional arguments to the String constructor are discarded and the result is a String object (not an array of strings). Commented Nov 18, 2013 at 0:23

3 Answers 3

3

You don't have a string array.

Try

var name=['Here','Is','Wasif'];


for(var i=0;i< name.length;i++)
        document.write(name[i]);
Sign up to request clarification or add additional context in comments.

1 Comment

I didn't think it was, and I was just going to comment! :)
0

You can check this code

var arr = name=['Here','Is','Wasif'];
for(var i=0;i<arr.length;i++){
document.write(arr[i]);
}

You can try your code here : http://jsfiddle.net/4Sgh5/

Comments

0

You could also use array join. A bit more simple that a for loop.

var arr = ['Here', 'Is', 'Wasif'];
document.write(arr.join(' '));

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.