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 

+ Report
Total Preview: 860
Briefly describe JavaScript core Array method unshift() with an example.
Copyright © 2024. Powered by Intellect Software Ltd