I am facing some issue with ethereum. web3.eth.accounts[0] or web3.eth.accounts is not working. When I tried console.log(web3.eth.accounts[0]), it returns undefined. But when I use console.log(web3.eth), I can see all the data in the console.
<html>
    <head>
        <title>TEST</title>
    </head>
    <body>
        <script>
            window.addEventListener('load', function(){
                if( typeof web3 !='undefined'){
                    console.log('web3 detected');
                    web3 = new Web3(web3.currentProvider);                                    
                    console.log(web3.eth.accounts);
                }else{
                    alert("please install MetaMask");
                }
            });
                       
        </script>
    </body>
</html>