Post

2 followers Follow
0
Avatar

Get all category fields in a app

Hi, I'm doing a calculation as below. Is it possible to add all category fields automatically to the array to check? Now I have to reference them one by one and it's easy to forget if you update the app.

var data = new Array(Test install in clean setup, Stock reduced on products, Stock reduced on products with sub products);
var percentage = new Array();
for (var index = 0; index < data.length; index++) {
if (data[index] == 'Approved') {
percentage.push(1);
} else if (data[index] == 'Not Approved') {
percentage.push(0);
} else {
percentage.push(0);
}
}
var sum = 0;
for (var i = 0; i < percentage.length; i++) {
sum += percentage[i];
}
var avg = (sum / percentage.length) * 100;
avg;

Andreas Johansson

Please sign in to leave a comment.