diff --git a/JS-Array-Slice-&-Splice.html b/JS-Array-Slice-&-Splice.html new file mode 100644 index 0000000..f865891 --- /dev/null +++ b/JS-Array-Slice-&-Splice.html @@ -0,0 +1,407 @@ + + + + + + JS Array Slice & Splice + + + +

JS Array Slice & Splice

+

Array slice()

+

+ The slice() method returns selected elements in an + array, as a new array. +

+

+ The slice() method selects from a + given start, up to a (not inclusive) + given end. +

+

+ The slice() method does not change the original + array. +

+

Syntax

+
array.slice(start, end)
+
+

Parameters

+ + + + + + + + + + + + + + + + +
ParameterDescription
start + Optional.
+ Start position. Default is 0.
+ Negative numbers select from the end of the array. +
end + Optional.
+ End position. Default is last element.
+ Negative numbers select from the end of the array. +
+
<!DOCTYPE html>
+<html>
+<head>
+  <title>JavaScript</title>
+  <script>
+    var a = ["Sanjay", "Aman", "Rehman","Rahul", "Karan"];
+    document.write(a + "<br><br>");
+    var b = a.slice(1 , 4);
+    document.write(b);
+  </script>
+</head>
+<body>
+
+</body>
+</html>
+
+

 

+
+

Array splice()

+

+ The splice() method adds and/or removes array + elements. +

+

+ The splice() method overwrites the original array. +

+
+

Syntax

+
array.splice(index, howmany, item1, ....., itemX)
+
+

Parameters

+ + + + + + + + + + + + + + + + + + + + +
ParameterDescription
index + Required.
+ The position to add/remove items.
+ Negative value defines the position from the end of the array. +
howmany + Optional.
+ Number of items to be removed. +
item1, ..., itemX + Optional.
+ New elements(s) to be added. +
+
<!DOCTYPE html>
+<html>
+<head>
+  <title>JavaScript</title>
+  <script>
+    var a = ["Sanjay", "Aman", "Rehman", "Rahul"];
+    document.write(a + "<br><br>");
+    a.splice(2,0,"Neha","Karan");
+    document.write(a);
+  </script>
+</head>
+<body>
+
+</body>
+</html>
+
+
+ + + diff --git a/google899ab52cad8d25e1(1).html b/google899ab52cad8d25e1(1).html index aa02675..917e89e 100644 --- a/google899ab52cad8d25e1(1).html +++ b/google899ab52cad8d25e1(1).html @@ -1 +1 @@ -google-site-verification: google899ab52cad8d25e1.html \ No newline at end of file +google-site-verification: google899ab52cad8d25e1.html diff --git a/index.html b/index.html index 742274d..d040f9d 100644 --- a/index.html +++ b/index.html @@ -112,6 +112,9 @@

JS NOTES

  • JS Array Concat & Join
  • +
  • + JS Array Slice & Splice +