How to create string with multiple spaces in JavaScript

前端 未结 5 641
北海茫月
北海茫月 2020-12-08 06:37

By creating a variable

var a = \'something\' + \'        \' + \'something\'

I get this value: \'something something\'.

5条回答
  •  情话喂你
    2020-12-08 07:10

    In 2020 - use ES6 Template Literals for this task. If you need IE11 Support - use a transpiler.

    let a = `something       something`;
    

    Template Literals are fast, powerful and produce cleaner code.


    If you need IE11 support and you don't have transpiler, stay strong

提交回复
热议问题