Write jquery element inside array

I declared an array variable els = []; in which I want to save jquery elments that are created at some point during certain events:

 els[file.id] = $('<li></li>'); $('body').append(els[file.id]); 

file.id is a unique identifier created by the plupload script that I use (event from it)

But it does not work, the array is always empty ...

+6
source share
1 answer

Arrays can only have sequential numeric keys. You cannot select arbitrary keys. To use arbitrary key-value pairs, use an object:

 var els = {}; 

With that said, the code you wrote should still work (although els.length will be 0) - maybe this is not a complete code sample?

+4
source

Source: https://habr.com/ru/post/902581/


All Articles