How I would do this:
// function you can use:
function getSecondPart(str) {
return str.split('-')[1];
}
// use the function:
alert(getSecondPart("sometext-20202"));
More Related Contents:
- phone number validation in js [closed]
- When is .then(success, fail) considered an antipattern for promises?
- What is the JavaScript >>> operator and how do you use it?
- Multi-row insert with pg-promise
- Dealing with float precision in Javascript [duplicate]
- Render basic HTML view?
- Memory leak risk in JavaScript closures
- Pretty printing XML with javascript
- Using querySelectorAll to retrieve direct children
- JavaScript double colon (bind operator)
- Get function name in JavaScript
- What do the different readystates in XMLHttpRequest mean, and how can I use them?
- How to auto-scroll to end of div when data is added? [duplicate]
- Bootstrap datepicker disabling past dates without current date
- What reason is there to use null instead of undefined in JavaScript?
- Does Javascript slice method return a shallow copy?
- Most modern method of getting mouse position within a canvas in native JavaScript [duplicate]
- Disable elastic scrolling in Safari [duplicate]
- Is there a way to get Chai working with asynchronous Mocha tests?
- A plain JavaScript way to decode HTML entities, works on both browsers and Node
- ScrollTo function in AngularJS
- Deobfuscating Javascript [closed]
- Is there a good use case for the constructor property in Javascript?
- javascript close current window
- Programmatically creating an SVG image element with javascript
- jQuery: noConflict
- ASP.NET MVC Partial view ajax post?
- Disable images in Selenium Python
- Return value of Promise’s resolve/reject functions
- How to get the total depth of an unknown JSON hierarchy?