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

GITEX Dubai Talk by Saion Gupta and Saiasmi Gupta

Good morning, everyone. I'm Saion Gupta, the Founder of 10xCoderKids and the Guinness World Record holder for the youngest computer prog...