View: array_unshift

Function:
Description: Pushes elements onto the beginning of the array.
Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function array_unshift (array) {
    // http://jsphp.co/jsphp/fn/view/array_unshift
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Martijn Wieringa
    // +   improved by: jmweb
    // %        note 1: Currently does not handle objects
    // *     example 1: array_unshift(['van', 'Zonneveld'], 'Kevin');
    // *     returns 1: 3
    var i = arguments.length;

    while (--i !== 0) {
        arguments[0].unshift(arguments[i]);
    }

    return arguments[0].length;
}
Comment on array_unshift version 47
Tests
Benchmark
[top]

Comments

There are no comments yet, be the first!

Please Login or Register to post comments.