Remove array delimiters

前端 未结 5 1473
终归单人心
终归单人心 2021-01-18 23:51

Is it possible remove delimiters when you array.toString? (javascript)

var myArray = [ \'zero\', \'one\', \'two\', \'three\', \'four\', \'five\' ];
var resul         


        
5条回答
  •  日久生厌
    2021-01-19 00:09

    You could use join instead of toString -

    var myArray = [ 'zero', 'one', 'two', 'three', 'four', 'five' ];
    var result = myArray.join('');
    

    join will join all the elements of the array into a string using the argument passed to the join function as a delimiter. So calling join and passing in an empty string should do exactly what you require.

    Demo - http://jsfiddle.net/jAEVY/

提交回复
热议问题