Implementation of JavaScript shift() function


Took 13 minutes and 24 seconds to implement JavaScript shift() function. Here is the code snippet.

Function:
arr=['a', 'b', 'c'];

function shift(arr) {
for (var i = 0; i < arr.length; i++) {
arr[i] = arr[i+1];
}
arr.pop();
return arr;
}

shift(arr);
document.write(arr);

Result:
b,c

No comments:

Post a Comment

Coding for Kids

What is coding? In coding we build a program to do a specific task for us. Code: A code is a set of computer instructions and when you will ...