I am trying to do a little work in JavaScript and am new to the language, but not to program languages.
class Key{
constructor(nm, keydata) {
var name = nm;
var data = keydata;
}
}
var KeySet = [];
for (i=0; i<5; i++){
KeySet.push(new Key("item " + i, "some data for " + i));
}
for (i=0; i<5; i++){
console.log(i,KeySet[i].name," ->",KeySet[i].data)
}
I am getting this at the console:
0 undefined -> undefined 1 undefined -> undefined 2 undefined -> undefined 3 undefined -> undefined 4 undefined -> undefined
- Can I even build an array of objects?
- If so, what is wrong with the above? What is the best way?
- Do I have to do anything like cast the array item contents to a Key object to use it? How?