How to implement hump-type and hyphen-conversion functions in JS?

Source: Internet
Author: User
Tags vars

This paper illustrates the hump-type and hyphen-conversion function of JS. Share to everyone for your reference, specific as follows:

On the Internet to find this paragraph, more like

1. Hump Transfer character:

VARs = "Foostylecss";
s = S.replace ([[A-z])/g, "-$1"). toLowerCase ();
Use regular to replace, concise and clear, very good

2. Turn Hump

vars1 = "Foo-style-css";
S1 = S1.replace (//-(/w)/g, function (all, letter) {
Returnletter.touppercase ();
});

It's not quite clear what this 2 looks.

So I write one, ^_^, this is easy to understand, is the code a bit more:

VARs = "Style-sheet-base";
Vara = S.split ("-");
Varo = a[0];
for (vari=1;i<a.length;i++) {
o = O + a[i].slice (0,1). toUpperCase () + a[i].slice (1);
}

Write another, this time with a regular:

vars1 = "Style-sheet-base";
S1 = S1.replace (//-(/w)/g, function (x) {return X.slice (1). toUpperCase ();});

Haha, interesting.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.