Animations

API

Arrays

Async

Basics

Challenges

Classes

Console

Dates

Debugging

DOM Elements

DOM Methods

DOM Navigation

DOM Properties

Event Listeners

Flow Control

Forms

Functions

Global Functions

JSON

Keywords

Libraries (3rd party)

Math

Modules

Objects

Snippets

String

Types

Widgets

Window Object

JavaScript - indexOf()

https://www.w3schools.com/jsref/jsref_obj_array.asp

The indexOf() also works with arrays. You can use it to determine if something is found within an array. If it is NOT found, it will return a -1. "0" is actually the very first position (zero based) so it's possible o is return as a positive test.


    // The result of a will be “2” meaning that "Apple" is located at position 2 in the array.
    let fruits = ["Banana", "Orange", "Apple", "Mango"];
    let a = fruits.indexOf("Apple");
    document.getElementById("demo").innerHTML = a;

results: