Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

<html> <head> <title>array operation</title> <script type="text/javascript"> var…

  1. 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);

  2. 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:

    1. LENGTH OF ARRAY: The code displays the length of the array "mystring" using the "length" property.

    2. CONCATENATION: The code uses the "concat" method to concatenate the elements of "mystring" with the strings "development" and "tool".

    3. PUSH OPERATION: The code uses the "push" method to add the string "LANG" to the end of the "mystring" array.

    4. JOIN OPERATION: The code uses the "join" method to join the elements of the "mystring" array with the separator "->".

    5. POP OPERATION: The code uses the "pop" method to remove the last element from the "mystring" array.

    6. REVERSE OPERATION: The code uses the "reverse" method to reverse the order of the elements in the "mystring" array.

    7. SORT OPERATION: The code uses the "sort" method to sort the elements of the "mystring" array in alphabetical order.

    8. SHIFT OPERATION: The code uses the "shift" method to remove the first element from the "mystring" array.

    9. UNSHIFT OPERATION: The code uses the "unshift" method to add the string "THIS IS" to the beginning of the "mystring" array.

    10. 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.

  3. User

    Give me the output of the program

  4. 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