Skip to content

Instantly share code, notes, and snippets.

@ejknapp
Created December 13, 2009 15:56
Show Gist options
  • Select an option

  • Save ejknapp/255466 to your computer and use it in GitHub Desktop.

Select an option

Save ejknapp/255466 to your computer and use it in GitHub Desktop.
Searching An Array
1. A for loop that loops through the array
for (index = 0; index < numbers.length; index++) {
2. An "if" statement that compare the current element in the array with the value I'm searching for.
if (search === numbers[index])
3. A boolean variable to indicate that I've found something.
var valueFound = false;
4. Set the boolean variable to true if when we find our value.
valueFound = true;
5. Then break out of the loop. This will leave the index set at the current element in the array.
6. An "if" statement for valueFound.
if (valueFound) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment