/ Published in: JavaScript

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
Array.prototype.switchus = function(a,b) { var x, y; for(var i = 0; i < this.length; i++) { if(a == this[i]) { x = i; } if(b == this[i]) { y = i; } } if(x && y) { this[x] = b; this[y] = a; return true; } else { return false; } } var a = [2,3,4,5,'ultimo elemento', 'mesmo']; result = a.switchus(4,'mesmo');
Comments
