オブジェクト内のすべての0.0値をプッシュしたいので、オブジェクト内の0.0値の数を数えることができます。これまで、すべての値(0.0を含む)をプッシュするコードを作成しましたが、今は0.0VALUEのみをプッシュしたいと思います。
たとえば
、['cm_per1']
2つの「0.0」がある場合はプッシュしたいので、final_results['ESL']['cm_per1']
呼び出すと「 2final_results['ESL']['cm_per1'].length
」と表示されます(に2つの「0.0」がある ため)
これまでに作成したものです>> http://jsfiddle.net/xKJn8/26/cm_per1
var data = {
"MyData": [
{
"cm_per1": "21.9",
"cm_per2": "31.8",
"tipe": "ESL"
},
{
"cm_per1": "8.6",
"cm_per2": "7.0",
"tipe": "ESL"
},
{
"cm_per1": "3.2",
"cm_per2": "0.0",
"tipe": "ESL"
},
{
"cm_per1": "0.0",
"cm_per2": "0.0",
"tipe": "ESL"
},
{
"cm_per1": "0.0",
"cm_per2": "0.0",
"tipe": "ESL"
}
]
};
var final_results = {},
type,
current_row= "";
for (var i=0; i<data.MyData.length; i++) {
current_row = data.MyData[i];
type = current_row.tipe;
//I want to count how many cm_per1 and cm_per2 that have 0.0 value
if (!final_results[type]) {
final_results[type] = {
"cm_per1": [],
"cm_per2": []
};
}
final_results[type].cm_per2.push(current_row.cm_per2);
final_results[type].cm_per1.push(current_row.cm_per1);
}
//but the result is it counts all cm_per1 and cm_per2, and what I need is only counts that have 0.0 value
console.log(final_results['ESL']['cm_per1'].length);