my array printing out length instead of contents. genuinely looked answer found none. here code:
<p id="para"> </p> var myarray = [1,2,3,4,5]; myarray = myarray.unshift('charlie'); document.getelementbyid('para').innerhtml = myarray;
i want array print out charlie,1,2,3,4,5 instead prints out 6. dumb thing doing wrong here?
reading the docs array.unshift says returns length of array.
the unshift() method adds 1 or more elements beginning of array , returns new length of new array.
you might want remove assign operator so
var myarray = [1, 2, 3, 4, 5]; myarray.unshift('charlie'); document.getelementbyid('para').innerhtml = myarray.join(',');
<div id="para"> </div>
Comments
Post a Comment