動的に生成された配列のプロパティをカウントしようとしています。配列プログラムは、次のようにオブジェクト内に作成されます。
state_list.push({name: state, undergrad: 0, grad: 0, total: 0, programs: []});
後者は次のように入力されます。
n = findWithAttr(state_list, 'name', state);
//n = the index of property "name" with value of "state" in state_list
if(!(program in state_list[n]["programs"])) {
state_list[n]["programs"][program] = 1;
} else {
state_list[n]["programs"][program]++;
}
次に、配列に配置されたプログラムの数を合計する必要があり、それを行うことを望んでいました。
programs = state.programs;
console.log(programs.length);
しかし、これは 0 を返します。
ログ(プログラム)の場合の配列は次のとおりです。
Array[0]
History, MA: 3
Info Assurance & Security, MS: 1
International Literacy, MED: 1
length: 0
__proto__: Array[0]
main.js:237
It seems like it is placing all the programs in the array as one string... or something. I would love to have them indexed and have the ability to iterate over them. Any suggestions?