I have a situation where I have 3 different arrays with a very large number of objects. I read a lot of questions and blog posts about this, but I still don't know when to use what.
PS! My biggest problem is that I need iteration and push (perfect for arrays), and also find if exists in the array and delete (more suitable for objects). No specific order is required.
I cannot allow to have the same object in array1and array1clicked
because they have to perform different actions.
When is the best way to use an object and an array in my example? What should I replace with an object and what should remain an array? I'm sure the number of objects in it also matters, right?
My current code is:
var array1 = [ 20 objects ];
var array1clicked = [];
var array2 = [ 250 objects ];
var array2clicked = [];
var array3 = [ 50 000 objects ];
var array3clicked = [];
objecthtml.click(function() {
array1clicked.push(thisobject);
var index = array1.indexOf(thisobject);
if (index > -1) {
array1.splice(index, 1);
}
}
var array1count = array1.length;
var array1clickedcount = array1clicked.length;
if(condition1) {
for(a = 0; a < array1count; a++) {
array1[a].div.style.visibility = 'hidden';
}
for(a = 0; a < array1clickedcount; a++) {
array1clicked[a].div.style.visibility = 'visible';
}
}
else if(condition2) {
for(a = 0; a < array1count; a++) {
array1[a].div.style.visibility = 'visible';
}
for(a = 0; a < array1clickedcount; a++) {
array1clicked[a].div.style.visibility = 'hidden';
}
}
source
share