I cant seem to do this in an elegant way, and I don't understand some of the behaviour I'm seeing.
I have my array stored in html like so:
<input type="hidden" id="myField" value="1,2,3,5,8,13">
To add a value I must do this, is this really the cleanest way to do this?
$('#myField').val($('#myField').val() + ',' + 21);
And to remove I value I have to do something like this:
newValues=$.grep($('#myField').val(), function(value) {
return value != 3;
});
$('#myField').val(newValues);
Apart from this does not work.....as I get the same behaviour as illustrated here:
If i do this:
$.grep('1,2,3',function(value){return value!=3;})
It returns this, why do I get these extra blank elements? How do I remove 3 from the hidden input?:
["1", ",", "2", ","]