admin管理员组

文章数量:1134573

By creating a variable

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

I get this value: 'something something'.

How can I create a string with multiple spaces on it in JavaScript?

By creating a variable

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

I get this value: 'something something'.

How can I create a string with multiple spaces on it in JavaScript?

Share Improve this question edited May 6, 2017 at 9:05 Kishore Sahasranaman 4,2204 gold badges26 silver badges51 bronze badges asked Nov 5, 2015 at 8:32 IstvánIstván 5,12710 gold badges40 silver badges67 bronze badges 2
  • 7 use \xa0 code for each ` ` space – Andrew Evt Commented Nov 5, 2015 at 8:33
  • 1 also can use   in html – abbasalim Commented Dec 26, 2022 at 8:14
Add a comment  | 

7 Answers 7

Reset to default 161

In 2022 - 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

本文标签: htmlHow to create string with multiple spaces in JavaScriptStack Overflow