Skip to content

Instantly share code, notes, and snippets.

@dnasca
Created September 24, 2015 02:53
Show Gist options
  • Select an option

  • Save dnasca/fb26dc02a9d30ae8f9af to your computer and use it in GitHub Desktop.

Select an option

Save dnasca/fb26dc02a9d30ae8f9af to your computer and use it in GitHub Desktop.
finding and pushing a string to an array
var text = "This string contains the name Derrik";
var myName = "Derrik";
var hits = [];
for(var i = 0; i < text.length; i++) {
if (text[i] === 'D') {
for(var j = i; i > (myName.length + i); j++) {
hits.push(text[j]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment