close

How to create string with multiple spaces in JavaScript

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How to create string with multiple spaces in JavaScript in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How to create string with multiple spaces in JavaScript in javascript. So Here I am Explain to you all the possible methods here.

How to create string with multiple spaces in JavaScript ?

  1. How to create string with multiple spaces in JavaScript ?

    create string with multiple spaces in JavaScript var a = 'something' + Array(10).fill('\xa0').join('') + 'something'
    number inside Array(10) can be changed to needed number of spaces

  2. create string with multiple spaces in JavaScript

    create string with multiple spaces in JavaScript var a = 'something' + Array(10).fill('\xa0').join('') + 'something'
    number inside Array(10) can be changed to needed number of spaces

Method 1

var a = 'something' + Array(10).fill('\xa0').join('') + 'something'

number inside Array(10) can be changed to needed number of spaces

Method 2

You can use the <pre> tag with innerHTML. The HTML <pre> element represents preformatted text which is to be presented exactly as written in the HTML file. The text is typically rendered using a non-proportional (“monospace”) font. Whitespace inside this element is displayed as written. If you don’t want a different font, simply add pre as a selector in your CSS file and style it as desired.

Ex:

var a = '<pre>something        something</pre>';
document.body.innerHTML = a;

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment