Reputation: 8710
I have the following:
setup : function(first, middle, last) {
// Clean input.
$.each([first, middle, last], function(index, value) {
??? = value.replace(/[\W\s]+/g, '').toLowerCase();
});
Is there a way I could get that to work? I've tried to figure out what to substitute instead of ???
(I've tried this
, index
, this[index]
, but can't seem to wrap my head around pointing to the original variables.
Thanks for any help.
Upvotes: 1
Views: 411
Reputation: 93694
To modify arrays, use $.map()
instead, and just return the new value:
var clean = $.map([first, middle, last], function(value, index) {
return value.replace(/[\W\s]+/g, '').toLowerCase();
});
Better, use the special arguments
object (as in Patrick's answer) in place of building a temporary array:
var clean = $.map(arguments, function(value, index) {
return value.replace(/[\W\s]+/g, '').toLowerCase();
});
Upvotes: 1
Reputation: 322572
Use the Arguments object.
setup : function(first, middle, last) {
var args = arguments;
$.each(arguments, function(index, value) {
args[index] = value.replace(/[\W\s]+/g, '').toLowerCase();
});
Example: http://jsfiddle.net/EfHQ2/
Upvotes: 2