Skip to Main Content

Find the Index of the First Occurrence in a String

Problem URL:Find the Index of the First Occurrence in a String

My Solution:

/**
 * @param {string} haystack
 * @param {string} needle
 * @return {number}
 */
var strStr = function(haystack, needle) {
    if (needle.length === 0) {
        return 0;
    }

    return haystack.indexOf(needle);
};

Let's Connect

Twitter GitHub LinkedIn