Javascript function variable going null outside loop
<p>Below is the code I want to be checked, not sure what i am doing wrong here, but the value of variable checkedValue is not working outside the for loop.</p>

<p>If I test from the part i've commented [i.e. inside for loop], its working.</p>

<p>I've tested with declaring the array variable as [0] as well to check if its having at least the initial value 0, but is not displaying anything, as if the variable is null.</p>

<pre><code>&lt;script&gt;
                    var checkedValue = [];
                    function getItemId() 
                    {
                        //var checkedValue = [];
                        var inputElements = document.getElementsByName('pick');
                    for(var i=0; i&lt;=inputElements.length; i++)
                    {
                        if(inputElements[i].checked)
                        {
                            checkedValue.push(inputElements[i].value);   
                        }
                    //document.getElementById("demo").innerHTML = checkedValue;
                    }
                    document.getElementById("demo").innerHTML = checkedValue;
                    }
                &lt;/script&gt;
</code></pre>