Quote:
|
Do you think it relevant enough to put into the 'Post A Javascript' section?
|
Up to you, although Logic Ali may have trumped you
Code:
var arr = [];
for (var i = group.length; i--; arr.unshift(group[i]));
return arr.map(function (obj) {
return (obj.checked) ? obj.value : false;
}).filter(function (obj) {
return (obj !== false);
});
I'm not suggesting this should be incorporated - there is no added value, I was just experimenting

.
A DOM
nodeList is
like an array but is
not an array - it's really a collection of objects. This code first stores (converts?) the nodeList to an array.
The array
map method creates another array by applying a function to every element of an array. In this instance, the new array contains either the value false, or the value of the input; that is, if it is checked.
The method
filter is then applied to the resultant array. This removes the false elements from the array, leaving only the values of those elements which were checked.
It is not really useful for this example. It could be useful if a lot more processing is done within the map or filter methods. Andy.