02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

indexOf vs. lastIndexOf

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.

Question: What is the difference between indexOf and lastIndexOf?

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.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!

Overview

02:27

new Array();

03:37

Array vs. Object

03:18

Setting a size to our Array

03:28

Starting Up With Content

02:18

Working With Arrays

08:36

Editing Array Data

07:07

push

03:48

unshift

03:11

Intergrating Into Our Mini App

04:54

pop and shift

05:51

indexOf vs. lastIndexOf

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.

09:29

splice

09:48

reverse

01:47

[]

01:47

Summary

01:30