Why doesn't .join() work with function arguments?

后端 未结 8 1616
遇见更好的自我
遇见更好的自我 2021-02-01 11:59

Why does this work (returns \"one, two, three\"):

var words = [\'one\', \'two\', \'three\'];
$(\"#main\").append(\'

\' + words.join(\", \") + \'

8条回答
  •  萌比男神i
    2021-02-01 12:24

    I don't know if there's a simple way to convert arguments into an array, but you can try this:

    var toreturn = "the list:";
    for(i = 0; i < arguments.length; i++)
    {
       if(i != 0) { toreturn += ", "; }
       toreturn += arguments[i];
    }
    

提交回复
热议问题