Hi all. I have a following source code php+js: http://pastebin.org/277948
I want to rewrite it using pure JS, but can’t imagine the way.
Any advices are appreciated.
Hi all. I have a following source code php+js: http://pastebin.org/277948
I want to rewrite it using pure JS, but can’t imagine the way.
Any advices are appreciated.
sorry dont know php but this is the javascript.
if (inp == true) {
for(i =0;i<numFields; i++){
do something with vals[i];
}
}
You can use the every
method to test if all elements in the array satisfy the predicate.
if (inp && vals.every(Boolean)) {
// or: vals.every(function(x){return x;})
...
}
But if you have to target browsers that does not support the every
method, you can evaluate the condition with a for loop.
if (inp) {
accept = true;
for (var i = vals.length-1; i >= 0; -- i)
if (!vals[i]) {
accept = false;
break;
}
if (accept) {
...
}
}