Convert hyphens to camel case (camelCase)

后端 未结 13 1875
梦谈多话
梦谈多话 2020-12-04 08:02

With regex (i assume) or some other method, how can i convert things like:

marker-image or my-example-setting to markerImage o

13条回答
  •  悲哀的现实
    2020-12-04 08:10

    Try this:

    var camelCased = myString.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
    

    The regular expression will match the -i in marker-image and capture only the i. This is then uppercased in the callback function and replaced.

提交回复
热议问题