<!DOCTYPE html> <html> <head> <title>Sample</title> <script> function main(){ /* */ var ary = ["banana", "mango", "watermelon", "apple"]; var str1 = ary.toString(); document.write("Comma-separated String: "+str1+"<br>"); /*at 2, delete nothing */ ary.splice(2, 0, "cherry"); str1 = ary.toString(); document.write("After splice(2, 0, \"cherry\"): "+str1+"<br>"); /* at 3, delete 2*/ ary.splice(3, 2); str1 = ary.toString(); document.write("After splice(3, 2): "+str1+"<br>"); ary.splice(1,1); str1 = ary.toString(); document.write("After splice(1,1): "+str1+"<br>"); } </script> </head> <body onload="main()"> </body> </html>
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more