JavaScript Array shift()


JavaScript shift() function , Array में से first element remove करता है। और removed element को ही return करता है।

JavaScript Array shift() Syntax

array.shift();

Parameters

  1. array | required : array variable , जिसमे से value remove करनी है।

  2. Return Value : removed element को ही return करता है।


अगर  Array empty है तो , undefined return होगा।

JavaScript Array shift() Example

File : js_array_shift.html

CopyFullscreenClose FullscreenRun
<!DOCTYPE html>
<html>
  <body>
    <script>
      var arr=['PHP', 'JavaScript', 'jQuery', 'Laravel']; 
      document.writeln("Removed Element : " +arr.shift() + "<br>");
      document.writeln("Remaining Elements : " + arr);
    </script>
  </body>
</html>
Output
Removed Element : PHP
Remaining Elements : JavaScript,jQuery,Laravel

Hey ! I'm Rahul founder of learnhindituts.com. Working in IT industry more than 4.5 years. I love to talk about programming as well as writing technical tutorials and blogs that can help to others .... keep learning :)

Get connected with me - LinkedIn Twitter Instagram Facebook