-
-
Save NKid/0d2a47593a335424ea93 to your computer and use it in GitHub Desktop.
join, split 應用
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getBaseName(str) { | |
var segs = str.split('.'); | |
if(segs.length > 1) segs.pop(); | |
return segs.join('.'); | |
} | |
function getExtension(str) { | |
var segs = str.split('.'); | |
if(segs.length <= 1) return ''; | |
return segs.pop(); | |
} | |
console.log(getBaseName('my.example.js')); //my.example | |
console.log(getExtension('my.example.js')); //js | |
var str = 'welcome_to_my_world'.split('_').join('-'); | |
console.log(str); //welcome-to-my-world | |
var str = 'welcome_to_my_world'.replace(/_/g, '-'); | |
console.log(str); //welcome-to-my-world |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment