const string = "XYZ 123 ABC 456 ABC 789 ABC";
function getPosition(string, subString, index) {
return string.split(subString, index).join(subString).length;
}
console.log(
getPosition(string, 'ABC', 2) // --> 16
)
More Related Contents:
- Fade animation while scrolling
- Fetch: POST JSON data
- What’s the effect of adding ‘return false’ to a click event listener?
- What does a script-Tag with src AND content mean?
- Chrome desktop notification example [closed]
- Detect rotation of Android phone in the browser with JavaScript
- Ajax, back button and DOM updates
- Async function not returning value, but console.log() does: how to do? [duplicate]
- Removing an item from a select box
- Add/remove class with jquery based on vertical scroll?
- How can I close a window with Javascript on Mozilla Firefox 3?
- Limit number of records that can be written to a path (reference other paths in security rules)
- Use functions defined in ES6 module directly in html
- How to quickly clear a JavaScript Object?
- Why does modulus operator return fractional number in javascript?
- Force download a pdf link using javascript/ajax/jquery
- My discord bot code is working but is not responding to my commands [duplicate]
- How to reach the element itself inside jQuery’s `val`?
- Literal notation VS. constructor to create objects in JavaScript [duplicate]
- Conditional comment for ‘Except IE8’?
- Is it possible to add Request Headers to an iframe src request?
- Javascript Convert Date Time string to Epoch
- getElementsByClassName onclick issue [duplicate]
- How can I detect shift + key down in javascript? [duplicate]
- How to chain ajax requests?
- Safe value must use [property]=binding after bypass security with DomSanitizer
- How do I unset an element in an array in javascript?
- Subtracting long numbers in javascript
- Precedence: Logical or vs. Ternary operator
- No sound on iOS 6 Web Audio API