Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8606431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:05:25+00:00 2026-06-12T03:05:25+00:00

In Javascript, the method to print out using console.log(this is %s and %s, foo,

  • 0

In Javascript, the method to print out using

console.log("this is %s and %s", foo, bar);

works, so it follows some C style, but it doesn’t follow

console.log("%*s this is %s and %s", 12, foo, bar);

where the %*s and 12 is to make it print out 12 spaces, as in this question: In Objective-C, how to print out N spaces? (using stringWithCharacters)

Is there a short, quick way to make it work simply in Javascript? (say, without using the sprintf open source library or writing a function to do it?)

Update:, in my case, 12 is actually a variable, such as (i * 4), so that’s why it can’t be hardcoded spaces inside the string.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:05:26+00:00Added an answer on June 12, 2026 at 3:05 am

    The easiest way would be to use Array.join:

    console.log("%s this is %s and %s", Array(12 + 1).join(" "), foo, bar);
    

    Note that you want N + 1 for the array size.


    I know you said you dont want functions, but if you do this a lot, an extention method can be cleaner:

    String.prototype.repeat = function(length) {
     return Array(length + 1).join(this);
    };
    

    This allows you to do:

    console.log("%s this is %s and %s", " ".repeat(12), foo, bar);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my javascript method in .aspx file. I want to invoke this method
I have a javascript method looks like this JSMethod(JS_para_1,JS_para_2) { ...... ,,,,, } and
I am using a Javascript method to sync the column widths of two tables.
I'm trying to find the jQuery equivalent of this JavaScript method call: document.addEventListener('click', select_element,
Probably a stupid question, but is there a Javascript method to browse another url,
Ok... First off, I know this isn't a new question. But, for some reason
Using Google Chrome, if you console.log an object, it lets you inspect the element
I have a PHP script that parses an array using the json_encode() method but
This seems like a very basic problem but I can't figure it out. I'm
I know very little about JavaScript but despite this I'm trying to cobble something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.