<!DOCTYPE html> <html> <body> <h1>JavaScript Arrays</h1> <h2>The indexOf() Method</h2> <p>indexOf() returns the position of a specified value in an array:</p> <p id="workingcode"></p> <script> const fruits = ["Java", "ServiceNow", "PHP", "JavaScript", "Angular"]; let index = fruits.indexOf("JavaScript"); document.getElementById("workingcode").innerHTML = index; </script> </body> </html>
Output:
JavaScript Arrays
The indexOf() Method
indexOf() returns the position of a specified value in an array:
3
indexOf() Method JavaScript
admin Changed status to publish December 19, 2023