how to use Indexof with array?
Loading
how to use Indexof with array?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Bhavesh JhaPosted Apr 1, 2024, 7:54 AM
Let us consider an array having name arr of string type.
Tuhin PaulPosted Mar 25, 2024, 10:56 AM
Starting the search from a specific index:
Tuhin PaulPosted Mar 25, 2024, 10:55 AM
Finding the index of a specific element:
o abuzaidPosted Mar 22, 2024, 7:34 PM
thanks all for your help
omran abuzaid
Gajendra JangidPosted May 12, 2022, 3:31 AM
The indexOf() method returns the first index (position) of a specified value.The indexOf() method returns -1 if the value is not found.The indexOf() method starts at a specified index and searches from left to right.By default the search starts at the first element and ends at the last.Negative start values counts from the last element (but still searches from left to right).
Example:
const fruits = ["Banana", "Orange", "Apple", "Mango", "Apple"];
let index = fruits.indexOf("Apple", -1);
Sachin SinghPosted May 11, 2022, 6:28 PM
Muhammad Imran AnsariPosted May 11, 2022, 4:48 PM