Since I had to remove some elements from my arrays, I followed a few pieces of code found in stackoverflow and came up with this one:
Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
For some reasons, however, this piece of code is being printed EVERYWHERE whenever something has something to with an array.
Example:
this piece of code:
Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
Scadenza.prototype.init = function() {
this.promemoria = (this.promemoria == "")?("NO"):(this.promemoria);
var gruppo = this.group; // convert array to string.
this.group = "";
for (var i in gruppo) {
if (i != (gruppo.length - 1)) {
this.group += gruppo[i] + ", ";
}
else {
this.group += gruppo[i];
}
}
alert(this.group);
};
This piece of code is supposed to convert the array this.group (stored temporarily in the variable "gruppo") into a string (that's quite obvious, I think).
It is, of course, doing it's job greatly, if it wouldn't be that its alert is:
[DATA NEEDED]function (from, to) { var rest = this.slice((to || from) + 1 || this.length); this.length = from < 0 ? this.length + from : from; return this.push.apply(this, rest); }
This piece of code is being also sent to a database through an AJAX request and the result of the query, at the desired coloumn, is this one:
function (from, to) { var rest = this.slice((to || from) + 1 || this.length); this.length = from < 0 ? this.length + from : from; return this.push.apply(this, rest); },
I'm quite surprised this is happening but I have ABSOLUTELY no idea on how to fix it.
No errors have been alerted while loading the page or when clicking the button that throws this event.
Any idea?
ps: Not sure if helps, but I'm using jQuery.
@comments:
The normal for loop actually doesn't fix this:
Scadenza.prototype.init = function() {
this.promemoria = (this.promemoria == "")?("NO"):(this.promemoria);
var gruppo = this.group; // convert array to string.
this.group = "";
for (var i = 0; i < gruppo.length; i++) {
if (i != (gruppo.length - 1)) {
this.group += gruppo[i] + ", ";
}
else {
this.group += gruppo[i];
}
}
alert(this.group);
};
Alert is still the same.