Javascript new Array and join() method

后端 未结 5 1789
北恋
北恋 2021-01-13 00:49

Inspired by this popular speech I wanted to figure out some issue related to creating arrays. Let\'s say I am creating new array with:

Array(3)

5条回答
  •  野的像风
    2021-01-13 01:21

    Join combines the elements in an array with the specified delimiter.

    So, since there are 3 elements, you only need 2 delimiters (between 1st and 2nd, and between 2nd and 3rd).

    var a = [1,2,3];
    a.join(','); //1,2,3
    a.join('test'); // 1test2test3
    

提交回复
热议问题