You can write if statement inline.
var a = 11; a == 10 ? alert("true") : alert("false");
Even more sophisticated
var isTen = (a == 10) ? "yes" : "no";
More generally, a good solution to deal with data and avoid loops is to
use functional patterns, like
map/reduce functions. It is
a bit tricky at the beginning but totally worth the effort. It really
makes your code clearer.
This text was originally published in quora.