<
body
style
=
"text-align:center;"
>
<
h1
style
=
"color:green;"
>
GeeksforGeeks
</
h1
>
<
p
id
=
"GFG_UP"
>
</
p
>
<
button
onclick
=
"myGFG()"
>
Click Here
</
button
>
<
p
id
=
"GFG_DOWN"
></
p
>
<
script
>
var arr = [0, 3, 1, 5, 2, 7, 4, 9, 10];
var up = document.getElementById("GFG_UP");
up.innerHTML =
"Alternative of Array splice() method in JavaScript."+
" <
br
>Array = [" + arr + "]";
var down = document.getElementById("GFG_DOWN");
function mySplice(arr, ind, ct) {
// if ct(count) not passed in function call.
if (typeof ct == 'undefined') {
ct = 1;
}
var rem = [];
while (ct--) {
var indRem = ind + ct;
//pushing the elements rem array
rem.push(arr[indRem]);
// removing the element from original array.
arr[indRem] = arr.pop();
}
// returning the removed elements
return rem;
}
function myGFG() {
down.innerHTML =
"Removed Elements - " + mySplice(arr, 4, 3);
}
</
script
>
</
body
>