Underscore.js _.camelCase() 方法
_.camelCase()方法用于将破折号分隔的字符串转换为驼峰式字符串
句法:
_.camelCase( dashedString );
参数:
- dashedString:此方法采用破折号分隔的字符串。
返回值:此方法返回转换后的 camelCase 字符串。
注意:这在普通 JavaScript 中不起作用,因为它需要安装 underscore.js contrib 库。 Underscore.js contrib 库可以使用npm install underscore-contrib –save 安装。
示例 1:
Javascript
// Defining underscore contrib variable
var _ = require('underscore-contrib');
var cml = _.camelCase( "a-ab-abc" );
console.log("The calmelCase String is : ", cml);
Javascript
// Defining underscore contrib variable
var _ = require('underscore-contrib');
var cml = _.camelCase( "geeks-for-geeks" );
console.log("The calmelCase String is : ", cml);
输出:
The calmelCase String is : aAbAbc
示例 2:
Javascript
// Defining underscore contrib variable
var _ = require('underscore-contrib');
var cml = _.camelCase( "geeks-for-geeks" );
console.log("The calmelCase String is : ", cml);
输出:
The calmelCase String is : geeksForGeeks