Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript array.prototype being printed almost everywhere
    primarykey
    data
    text
    <p>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:</p> <pre><code>Array.prototype.remove = function(from, to) { var rest = this.slice((to || from) + 1 || this.length); this.length = from &lt; 0 ? this.length + from : from; return this.push.apply(this, rest); }; </code></pre> <p>For some reasons, however, this piece of code is being printed EVERYWHERE whenever something has something to with an array.</p> <p>Example:</p> <p>this piece of code:</p> <pre><code>Array.prototype.remove = function(from, to) { var rest = this.slice((to || from) + 1 || this.length); this.length = from &lt; 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); }; </code></pre> <p>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).</p> <p>It is, of course, doing it's job greatly, if it wouldn't be that its alert is:</p> <blockquote> <p>[DATA NEEDED]function (from, to) { var rest = this.slice((to || from) + 1 || this.length); this.length = from &lt; 0 ? this.length + from : from; return this.push.apply(this, rest); }</p> </blockquote> <p>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:</p> <blockquote> <p>function (from, to) { var rest = this.slice((to || from) + 1 || this.length); this.length = from &lt; 0 ? this.length + from : from; return this.push.apply(this, rest); },</p> </blockquote> <p>I'm quite surprised this is happening but I have ABSOLUTELY no idea on how to fix it.</p> <p>No errors have been alerted while loading the page or when clicking the button that throws this event.</p> <p>Any idea?</p> <p>ps: Not sure if helps, but I'm using jQuery.</p> <p>@comments:</p> <p>The normal for loop actually doesn't fix this:</p> <pre><code>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 &lt; gruppo.length; i++) { if (i != (gruppo.length - 1)) { this.group += gruppo[i] + ", "; } else { this.group += gruppo[i]; } } alert(this.group); }; </code></pre> <p>Alert is still the same.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload