GeezerVison is showing github.com — Data structures Arrays Seraching README.md update · anubisant/JavaScript-Lessons@5eacaea
File tree
Expand file treeCollapse file tree
Open diff view settings
Data_Structures/Arrays/Searching
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: Data_Structures/Arrays/Searching/README.md +18-6Lines changed: 18 additions & 6 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 |  |
2 | 2 |
|
3 | 3 | # Searching |
4 | | -This MD file serves as example/template. It will be filled up soon. |
5 | | - |
6 | | -(for Bucky to fill up) |
| 4 | +In order to iterate an array more efficiently sometimes we have to search for the value instead of the place. The function **indexof()** helps us with that |
7 | 5 |
|
8 | 6 | # Course Documentation |
9 | 7 |
|
10 | | -(this for me to fill up with every element that you use in lessons. syntax explaination and links for more) |
11 | 8 |
|
12 | | -## Element to explain |
| 9 | +## .indexof() |
| 10 | +In our example: |
| 11 | + |
| 12 | + |
| 13 | + let items = [40, 68, 58, 12, 80, 37, 13, 63, 42, 3, 58]; |
| 14 | + console.log(items.indexOf(12)); // 3 |
| 15 | + console.log(items.indexOf(99)); // -1 (not found) |
| 16 | + console.log(items.indexOf(58)); // 2 |
| 17 | + console.log(items.lastIndexOf(58)); // 10 |
| 18 | + |
| 19 | + |
| 20 | +it is pretty forward that we use the function **.indexOF()** to find a specific value that is stored in our array. |
| 21 | +For finding the value "a" in the array "anarray" we are using the following syntax: |
| 22 | + |
| 23 | + anarray.indexOF("a") |
13 | 24 |
|
14 | | -(for example console.log) |
| 25 | + |
15 | 26 |
|
16 | 27 | ##Javascript functions |
17 | 28 |
|
@@ -125,4 +136,5 @@ stack in order to remove things from it. |
125 | 136 | - [Twitter](https://twitter.com/bucky_roberts) |
126 | 137 | - [Google+](https://plus.google.com/+BuckyRoberts) |
127 | 138 | - [reddit](https://www.reddit.com/r/thenewboston/) |
| 139 | + |
128 | 140 | > Written with [StackEdit](https://stackedit.io/). |