indexOf vs. lastIndexOf
<p>We know how to grab the last thing and the first thing but how do we find things in the middle. this is exactly where indexOf and lastIndexOf are very handy.</p> <h3>Question: What is the difference between indexOf and lastIndexOf?</h3> It's very simple: an array is like a line. imagine that there are 20 people standing in a line every one has there own name. when we ask for indexOf we start looking for "ben" from the start of the line starting at index 0 and going on until we find "ben" while when we use lastIndexOf we start from the end of the line. what's the catch you might be thinking. the best way to answer that is through a question "what if there are more then one 'ben' in the line? as it returns the index of the first thing it hits different values would return depending on our choice to start from the end or the start looking for that match. there are a few more layers to this and that we will explore more in the video.