JavaScript Example (Program)
Learn Details

Q. Where do use unshift() method ?

जिस array के first element से पहले Single या multiple element insert या add करना हो , तब unshift method का use करते हैं

array.unshift(item1, item2, ..., itemX)

  • Example


    <script>
    var a = ["Apple", "Ball", "Cat", "Dog"];
     document.write("<b> Before Medhod : </b>" +  a+"</br>");
     a.unshift("Elephant")
     document.write("<b> After Medhod : </b>" +  a);
       
    </script>
    Out Put : Before Medhod : Apple,Ball,Cat,Dog
    After Medhod : Elephant,Apple,Ball,Cat,Dog