String Array

An array with only string values is called string array.

Example

In the following example, we initialize an Array with strings, and access its elements using index.

index.html

</>
Copy
<!doctype html>
<html>
<body>
    <h2>JavaScript - String Array</h2>
    <pre id="output"></pre>
    
    <script>
        var names = ['apple', 'banana', 'cherry'];
        document.getElementById("output").innerHTML = names;
        document.getElementById("output").innerHTML += "names[2] : " + names[2];
    </script>
    
</body>
</html>