1. Question:Briefly describe JavaScript core Array method shift() with an example. 

    Answer
    Array.shift() method removes the first element in an array and returns it.Example:
    var stackWork=new Array("Lenny","Harold","Mary","Jean","Sal");
      var item=stackWork.shift();
      document.write(item);
      document.write("<br/>")
      document.write(stackWork);
    Output: Lenny Harold,Mary,Jean,Sal,Delia






    1. Report
  2. Question:Briefly describe JavaScript core Array method unshift() with an example. 

    Answer
    Array.unshift() method is similar to the push() method, except that the new element is put at the front of the array (bottom of the stack) and it returns the current length of the array.Example:
    var stackWork=new Array("Lenny","Harold","Mary","Jean","Sal");
      var item=stackWork.unshift("Willie");
      document.write(item);
      document.write("<br/>")
      document.write(stackWork);
    Output: 6 Willie,Lenny,Harold,Mary,Jean,Sal






    1. Report
  3. Question:Briefly describe JavaScript core Array method splice() with an example. 

    Answer
    Array.splice() is a method used to insert, delete, and substitute values in array elements. The method has three arguments, start, delete, and data. The starting position specifies where the new value (data) is to be inserted and where deletions begin. If no deletions are specified, the splice() method has the effect of inserting an element and value into an array.Example:
    var stackWork=new Array("Lenny","Harold","Mary","Jean","Sal");
     stackWork.splice(1,0,"Fred");  
     document.write(stackWork);
    Output: Lenny,Fred,Harold,Mary,Jean,Sal






    1. Report
Copyright © 2025. Powered by Intellect Software Ltd