Creating multiple arrays with different names in Javascript -


trying make little chat program, using click function create new containers (new channels chat in) , add them html page.

i want add array (the whitelist) every container create , name in way can call later, number of containers isn't limited i'll have variable or something.

i'm using 1 array of containers; code snippet:

i = 0; $('#newroom').click(function () {    chatroom = {};    chatroom.whitelist = [];    //making every whitelist unique here    //here creating other stuff    i++; }); 

i want call whitelist later like

document.getelementbyid('chatroom.whitelist' + i)

or similar, want differ between them names stored in 1 specific whitelist.

i don't know if there's more simple way since i'm new javascript sure hope you'll me.

your model not need unique id every whitelist. because add whitelist chatroom.

on other side code not working when want document.getelementbyid('chatroom.whitelist' + i)

because every click want add new chatroom. after 10 clicks have 10 chatrooms. if want select 3rd chatroom, going do? id needs on chatroom:

chatrooms = [];  $('#newroom').click(function () {    chatroom = {};    chatroom.whitelist = [];    id = chatrooms.length;    chatrooms.push(chatroom); }); //select 3rd chatroom chatr = chatrooms[2]; //get whitelist wl = chatr.whitelist; 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -