Is there a difference between:
var samples = {
"TB10152254-001": {
folderno: "TB10152254",
ordno: "001",
startfootage: "",
endfootage: "",
tagout: "Y"
},
"TB10152254-002": {
folderno: "TB10152254",
ordno: "002",
startfootage: "",
endfootage: "",
tagout: "Y"
},
"TB10152254-003": {
folderno: "TB10152254",
ordno: "003",
startfootage: "",
endfootage: "",
tagout: "Y"
}
};
AND
var samples = new Array();
samples["TB10152254-001"] = {
folderno: "TB10152254",
ordno: "001",
startfootage: "",
endfootage: "",
tagout: "Y"};
samples["TB10152254-002"] = {
folderno: "TB10152254",
ordno: "002",
startfootage: "",
endfootage: "",
tagout: "Y"
};
samples["TB10152254-003"] = {
folderno: "TB10152254",
ordno: "003",
startfootage: "",
endfootage: "",
tagout: "Y"
};
EDIT:
I will re-phrase the question:
How do I populate the hash dynamically?
I can’t do something like samples.TB10152254-003 because i TB10152254-003 is dynamic…so, is that even possible?
Both will work because an Array is a type of object. But there isn’t any advantage to using an Array this way, and can easily give trouble when you iterate over the properties using a
for/in.The Object would be the proper type to use for named properties. Reserve your use of Array for index properties only.
With regard to your edit, you can dynamically populate the Object the same way as the Array, using square bracket notation.