sorry for noobie question. Can you explain please, what is the difference between:
1. var a = [];
a[\'b\'] = 1;
2. var a = {};
a[\'b\'] = 1;
>
1) Is an Array 2) Is an Object
With Array all is usual as in other languages
With Object also. - You can get value a.b == 1 - But in JS you can also get value with such syntax a["b"] == 1
you can write like this
function some(f){
var Object = {name: "Boo", age: "foo"}, key;
if(f == true){
key = "name";
}else{
key = "age";
}
return Object[key];
}
but I want to use it as collection, which I have to choose?
This depends of what data you want to store