CARVIEW |
Select Language
HTTP/2 307
date: Sat, 11 Oct 2025 21:34:03 GMT
content-type: text/html
content-length: 59
location: https://how.dev/answers/what-is-array-indexof-in-javascript
cf-ray: 98d17ab4890ef473-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: 48e6c30c2f95de8153b117d3a564e956
via: 1.1 google
alt-svc: h3=":443"; ma=86400
cf-cache-status: MISS
set-cookie: __cf_bm=33NPhtrc9JLZnKOpfcUGPcPY9mcMPKFo14sFk7jXptw-1760218443-1.0.1.1-IEV6lKvsFWP9h.dVqoRybl8Hh.sv50J.cPsHhrEFK15uL5izG.pzOUdS0xxCbGVCsYz1VBw.EYtpoEm1_.uL2oDaYj4mWsU_nK6Pdlwc2qs; path=/; expires=Sat, 11-Oct-25 22:04:03 GMT; domain=.educative.io; HttpOnly; Secure; SameSite=None
vary: Accept-Encoding
strict-transport-security: max-age=31536000; includeSubDomains; preload
server: cloudflare
HTTP/2 200
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-middleware-rewrite: /answers/howdev/what-is-array-indexof-in-javascript
x-nextjs-cache: MISS
etag: W/"ahvne1ylgp6gu1"
content-type: text/html; charset=utf-8
x-cloud-trace-context: 95fcec61a2449c5f62ce6ee5204e34b3
date: Sat, 11 Oct 2025 21:34:04 GMT
server: Google Frontend
via: 1.1 google
vary: Accept-Encoding
content-encoding: gzip
x-cache-status: miss
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