Random Background Image

That’s how javascript treats single item arrays with strings.
Here’s a very simple example showing this, you can test yourself:

    <script>
        var imageUrl = ['img1.jpg'];
        
        var imgElement = document.createElement('img');
        imgElement.src = '/assets/img/'+imageUrl; 
        
        document.body.appendChild(imgElement);
    </script>

Also if you do a comparison:

['img1.jpg'] == 'img1.jpg'

returns true.

2 Likes