HTML Editor
<!DOCTYPE html> <html lang="en-US"> <body> <script> Array.prototype.toAlternateCase = function() { for (i = 0; i < this.length; i++){ //Get one Element, say, "Aston Martin" var oneElement=this[i]; var temp = ""; //Convertion takes place here for(j = 0; j < oneElement.length; j++){ if(j%2 == 0) temp += oneElement[j].replace(oneElement[j], oneElement[j].toUpperCase()); else temp += oneElement[j].replace(oneElement[j], oneElement[j].toLowerCase()); } //Replace Actual string with Converted string this[i]= temp; } }; var myCar = ["Aston Martin","Jaguar","Maserati"]; myCar.toAlternateCase(); document.write(myCar[0]); </script> </body> </html>
OUTPUT
×

Save as Private