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 8073973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:30:26+00:00 2026-06-05T14:30:26+00:00

Is there a possibility to wrap each character in Javascript and prepend zero’s if

  • 0

Is there a possibility to wrap each character in Javascript and prepend zero’s if its less then X digits?

What i get/have:

var votes = 2;
//or
var votes = 123;
//or
var votes = 4321;

what it should to look like:

<span>0</span><span>0</span><span>0</span><span>2</span>
//or
<span>0</span><span>1</span><span>2</span><span>3</span>
//or
<span>4</span><span>3</span><span>2</span><span>1</span>

so the result should be a number with four digits.

  • 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-05T14:30:28+00:00Added an answer on June 5, 2026 at 2:30 pm

    here’s a tricky version:

    var votes = 123;
    ("0000" + votes).slice(-4); /* 0123 */
    

    thus, to wrap each digit in a <span> you could fetch each digit with $.map and wrap it into its own element, like in this example fiddle: http://jsfiddle.net/cZAWj/

    var votes = 973;
    
    $.map(("0000" + votes).slice(-4), function(digit) {
        $('<span/>', { text : digit }).appendTo($('body'));
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any possibility in the prefix-function of a given pattern to have something
Is there any possibility to use old Ada code in Android? I have an
Is there possibility to narrow context for include. For example, I have for tag
Is there any possibility to get all HTML content elements that contains plain text
is there any possibility to have a generic List<System.Type> and to have a constraint
is there a possibility to get on an IPhone the connected WIFI SSID with
Is there a possibility in Java to get rid of the necessity to catch
Is there a possibility to get my displayed page's contents in as-is format into
I want to know, is there the possibility to ask Unity do not wrap
is there a possibility to prevent a textblock from resize it's parent? I have

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.