Implementation of JavaScript push() method


Took 1 minute and 26 seconds to make this JavaScript push() method. Here is the code snippet.

Code:
arr = [1, 2, 3]
function push(arr, val) {
arr[arr.length] = val;
}

push(arr, 4);
document.write(arr);

Result:
1,2,3,4

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 ...