JavaScript Array slice()

📔 : Java Script 🔗

slice() method , दिए गए start - end argument के according elements को select करके एक new Array Object return करता है। हालाँकि इससे original Array में कोई changes नहीं आते हैं।

JavaScript Array slice Syntax

array.slice(start : int, end : int);

  1. start | required : यह starting value है , जहाँ से Array elements को select करना है। input value का type integer होना चाहिए।

  2. end | optional : यह end value है , जहाँ तक Array elements को select करना है।इसका type भी integer होना चाहिए।

  3. Return Value : दिए गए input के according , एक selected elements का एक new Array return करता है।

JavaScript Array slice Example

File : js_array_slice.html

CopyFullscreenClose FullscreenRun
<!DOCTYPE html>
      let languages = ["PHP", "Java", "JavaScript", "Python", "Ruby", "React JS", "React Native"]; 
      /*It will select from array indx 2 to end*/
      /*line break*/
      /*It will select from array indx 2 to 3 : end*/
      document.write(languages.slice(2, 4));
      document.write("Original Array : " + languages);
JavaScript,Python,Ruby,React JS,React Native
Original Array : PHP,Java,JavaScript,Python,Ruby,React JS,React Native

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook