jQuery.each()
Variations on jQuery.each()
by b9chris
HTML
<button>Run</button>
<div id=output></div>
CSS
body {
font-family: Verdana;
}
JavaScript
$('button').click(function() {
// Demo code
var array = ['a', 'b', 'c'];
// Build our hashset
var hashset = {};
$.each(array, enableFlag, [hashset]);
// Check values in the hashset
$.each(['a', 'b', 'c', 'd'], function() {
if (hashset[this])
say(this + ': allowed');
else
say(this + ': forbidden');
});
});
function enableFlag(flags) {
flags[this] = true;
}
function say(s) {
var output = $('#output');
output.html(output.html() + s + '<br/>');
}