JSFiddle - React, Tailwind, and code Playground

JavaScript

var haystack1 = "fox fox fox";
var haystack2 = "ox fox fox";
var needle = "fox";

alert(haystack1.lastIndexOf(needle, 0) === 0);
alert(haystack2.lastIndexOf(needle, 0) === 0);