0

I need to style my JavaScript number string so would it be possible I can convert/split string and assign style . I tried split but need to know correct regular expression.

Example:

input: 22222

output: <p>2</p><p>2</p><p>2</p><p>2</p><p>2</p>

Thanks

1 Answer 1

1
'22222'.split('').map(function(x) {
    return '<p>'+x+'</p>';
}).join('');

Output: <p>2</p><p>2</p><p>2</p><p>2</p><p>2</p>

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, Could you please explain what is x argument in this function?
also map() function does not support by IE8 ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.