This is a
playground to test code. It runs a full
Node.js environment and already has all of
npm’s 400,000 packages pre-installed, including
nth-indexof with all
npm packages installed. Try it out:
This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.
Find the nth position of a pattern in a string.
str.indexOf(pattern) except that you can choose how many
pattern you wish to skip before getting the index.
npm install nth-indexof --save
const indexOf = require('nth-indexof') const text = 'foo\nbar\nbaz' console.log('The index of the 2nd linebreak is:', indexOf(text, '\n', 1)) // => 7
index = indexOf(haystack, needle[, skip][, offset])
Returns the index of the
needle in the
haystack ignoring the first
skip occurrences indicated.
haystack- A string in which to search
needle- The string to search for
skip- Optional number of instances of
needleto skip before finding the next index (default:
offset- Optional offset in the
haystackfrom where to start the search
-1 if no match is found.