CARVIEW |
Select Language
HTTP/2 307
date: Sun, 12 Oct 2025 06:45:09 GMT
content-type: text/html
content-length: 59
location: https://how.dev/answers/what-is-array-indexof-in-javascript
cf-ray: 98d4a1fc0e20741b-BLR
cache-control: public, max-age=300, stale-while-revalidate=604800
referrer-policy: strict-origin-when-cross-origin
x-app-version: v251008-h-251010-1202
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-app-type: Learn
x-robots-tag: all
x-nextjs-cache: MISS
x-cloud-trace-context: 35244f7fd1993356e2725d66aeeff7b9;o=1
via: 1.1 google
alt-svc: h3=":443"; ma=86400
cf-cache-status: EXPIRED
set-cookie: __cf_bm=52scDYRR3Q3hoD0rPYWuh2zv5vh1uOsFipIa4PbZaVw-1760251509-1.0.1.1-vV2_yqZFRwycTxcz7CLRPqA57JE2KyFERHz7dEnBbdUiCJ5BHxhZvqXsGGfUPQE3jrC5VXjpSKDF5J6m9P3hOG3T3HbRQp7wo3wDxtm99i4; path=/; expires=Sun, 12-Oct-25 07:15:09 GMT; domain=.educative.io; HttpOnly; Secure; SameSite=None
vary: Accept-Encoding
strict-transport-security: max-age=31536000; includeSubDomains; preload
server: cloudflare
HTTP/2 200
referrer-policy: strict-origin-when-cross-origin
x-app-version: v251008-h-251010-1202
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-app-type: Learn
x-middleware-rewrite: /answers/howdev/what-is-array-indexof-in-javascript
x-nextjs-cache: MISS
x-cloud-trace-context: 95fcec61a2449c5f62ce6ee5204e34b3
server: Google Frontend
via: 1.1 google
content-encoding: gzip
date: Sat, 11 Oct 2025 21:34:04 GMT
cache-control: public, max-age=300, stale-while-revalidate=604800
etag: W/"ahvne1ylgp6gu1"
content-type: text/html; charset=utf-8
vary: Accept-Encoding
content-length: 54995
age: 33065
x-cache-status: stale
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
What is array indexOf() in Javascript?
What is array indexOf() in Javascript?
Overview
The indexOf
function in Javascript is used to find the index of a particular key in the array. The general syntax for indexOf
is:
array.indexOf(keyName);
Parameters
The function indexOf
takes one single mandatory input as an argument. The mandatory input is the name of the key we want the index of.
Return value
The function indexOf
returns the index of the key.
Example
The following example will help you understand the function indexOf
more clearly. First, we create an array of names. Then, we use the function indexOf
to find the index of the name “Sana.” Lastly, we print the index.
const names = ["Samia", "Sana", "Ali"];const ind = names.indexOf("Sana");console.log(ind);
Relevant Answers
Explore Courses
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved