Skip to content

Commit 6e0a751

Browse files
committed
Add spliced method.
1 parent ad74962 commit 6e0a751

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>
5+
Spliced in Array Prototype To Return Original Array Reference
6+
</title>
7+
</head>
8+
<body>
9+
10+
<h1>
11+
Spliced in Array Prototype To Return Original Array Reference
12+
</h1>
13+
14+
<script type="text/javascript">
15+
16+
// This does the same exact thing as .splice(); but, it returns the original
17+
// array reference rather than the collection of items that were deleted.
18+
Array.prototype.spliced = function() {
19+
20+
// Returns the array of values deleted from array.
21+
Array.prototype.splice.apply( this, arguments );
22+
23+
// Return current (mutated) array array reference.
24+
return( this );
25+
26+
};
27+
28+
29+
// -------------------------------------------------- //
30+
// -------------------------------------------------- //
31+
32+
33+
// Logs the value, "0.a.b.1.2.3.4.x.y.5"
34+
console.log(
35+
"0.1.2.3.4.5"
36+
.split( "." )
37+
.spliced( 1, 0, "a", "b" )
38+
.spliced( -1, 0, "x", "y" )
39+
.join( "." )
40+
);
41+
42+
</script>
43+
44+
</body>
45+
</html>

index.htm

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ <h1>
1313
</h1>
1414

1515
<ul>
16+
<li>
17+
<a href="./demos/spliced-in-array-prototype/">Spliced in Array Prototype To Return Original Array Reference</a>
18+
</li>
1619
<li>
1720
<a href="./demos/eval-async-affects-performance-angularjs/">Looking At How scope.$evalAsync() Affects Performance In AngularJS Directives</a>
1821
</li>

0 commit comments

Comments
 (0)