Encapsulation function: turn a string into camel case naming

03 Encapsulation function: change a string into camel case naming

  Use an array to perform a split

  There are characters here, such as element is also an array, you can use charAt () to

  First split this to say split

  After that, the first letter of each word should be capitalized and then stitched together. Operate on a word first, and turn big problems into small ones, and then solve them later.

  Taking element as an example, arr [1] gets element. CharAt (0) gets this e, then toUpperCase () becomes uppercase.

  If there is a little blur, just check the document directly.

  After a solution, the for loop, var = 1, from the beginning, the first letter is not capitalized.

  Then assign Element to arr [1], then assign By to arr [2], and then assign Id to arr [3].

So that the whole is very clear

  The difference between the two is that a split converts the array into a string, and a join converts the character array into an array.

  Be sure to write about it.

  Then we encapsulate a function to a formal parameter, call this function, and pass an actual parameter.

  Then give a return value

  After returning, you still have to give him a console.log or show where.

  If you don't write the console.log, you just call and execute the function, which is not displayed, and you can also alert.

Published 11 original articles · praised 0 · visits 244

Guess you like

Origin blog.csdn.net/Douglas_Ryan_/article/details/105227608
Recommended