_.replace
returns a new string with some or all matches of a pattern
replaced by a replacement
- // Lodash
- var re = /apples/gi;
- var str = 'Apples are round, and apples are juicy.';
- var newstr = _.replace(str, re, 'oranges');
- console.log(newstr);
- // output: 'oranges are round, and oranges are juicy.'
- // Native
- var re = /apples/gi;
- var str = 'Apples are round, and apples are juicy.';
- var result = str.replace(re, 'oranges');
- console.log(result);
- // output: 'oranges are round, and oranges are juicy.'
Browser Support for String.prototype.replace()
✔ | ✔ | 1.0 ✔ | ✔ | ✔ | ✔ |
当前内容版权归 you-dont-need 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 you-dont-need .