Edit in JSFiddle
JavaScript
var strToArray = str.split(" "); var elementToDelete = strToArray.indexOf(before); //Outputs index 4