<html> <head> <title>array operation</title> <script type="text/javascript"> var…
- User
var mystring=new Array(2); mystring[0]="WEB"; mystring[1]="PROGRAM"; mystring[2]="BCA";
document.writeln(" Array operations");
document.writeln("ORIGINAL STRING is "); for(var i=0;i< mystring.length;i++) { document.writeln("" +mystring[i]+""); } document.writeln(""); document.writeln(""+"1.LENGTH OF ARRAY :"+mystring.length); var newstr=mystring.concat("development","tool"); document.writeln(""+"2.CONCATENATION :"+" "+newstr); mystring.push("LANG"); document.writeln(""+"3.PUSH OPERATION :"+" "+mystring); var n1=mystring.join("->"); document.writeln(""+"4.JOIN OPERATION :"+" "+n1);
mystring.pop(); document.writeln("<b><br/>"+"5.POP OPERATION :"+" "+mystring); mystring.reverse(); document.writeln("<b><br/>"+"6.REVERSE OPERATION :"+" "+mystring); mystring.sort();document.writeln(""+"7.SORT OPERATION :"+" "+mystring); mystring.shift(); document.writeln(""+"8.SHIFT OPERATION :"+" "+mystring); mystring.unshift("THIS IS "); document.writeln(""+"9.unSHIFT OPERATION :"+" "+mystring);
document.writeln(""+"10.BEFORE SPLICE OPERATION :"+" "+mystring); var newarray=mystring.splice(0,0); document.writeln(""+"10.SPLICE OPERATION :"+" "+mystring);
- Assistant
The code above is written in HTML and JavaScript and performs various operations on an array called "mystring". Here is a breakdown of each operation:
-
LENGTH OF ARRAY: The code displays the length of the array "mystring" using the "length" property.
-
CONCATENATION: The code uses the "concat" method to concatenate the elements of "mystring" with the strings "development" and "tool".
-
PUSH OPERATION: The code uses the "push" method to add the string "LANG" to the end of the "mystring" array.
-
JOIN OPERATION: The code uses the "join" method to join the elements of the "mystring" array with the separator "->".
-
POP OPERATION: The code uses the "pop" method to remove the last element from the "mystring" array.
-
REVERSE OPERATION: The code uses the "reverse" method to reverse the order of the elements in the "mystring" array.
-
SORT OPERATION: The code uses the "sort" method to sort the elements of the "mystring" array in alphabetical order.
-
SHIFT OPERATION: The code uses the "shift" method to remove the first element from the "mystring" array.
-
UNSHIFT OPERATION: The code uses the "unshift" method to add the string "THIS IS" to the beginning of the "mystring" array.
-
SPLICE OPERATION: The code uses the "splice" method to remove 0 elements from the "mystring" array starting at index 0.
The results of each operation are displayed using the "writeln" method.
-
- User
Give me the output of the program
- Assistant
The output of the program would be:
Array operations
ORIGINAL STRING is WEB PROGRAM BCA
1.LENGTH OF ARRAY : 3 2.CONCATENATION : WEB,PROGRAM,BCA,development,tool 3.PUSH OPERATION : WEB,PROGRAM,BCA,LANG 4.JOIN OPERATION : WEB->PROGRAM->BCA->LANG 5.POP OPERATION : WEB,PROGRAM,BCA 6.REVERSE OPERATION : BCA,PROGRAM,WEB 7.SORT OPERATION : BCA,PROGRAM,WEB 8.SHIFT OPERATION : PROGRAM,WEB 9.unSHIFT OPERATION : THIS IS ,PROGRAM,WEB 10.BEFORE SPLICE OPERATION : THIS IS ,PROGRAM,WEB 10.SPLICE OPERATION : THIS IS ,PROGRAM,WEB