javascript – Why each doesn't work

Question:

Code

var datas=[];     
datas[pole]=text;
        $.each(datas, function (key, value) {
            alert(key+":"+value);
        });

for some reason, the alert is not displayed, the console is also silent

Answer:

The reason is that you declared an array and are trying to work with it as with an object, if you declare an object, then everything works:

var datas={};     
datas['pole']='text';
$.each(datas, function (key, value) {
  alert(key+":"+value);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Scroll to Top