Function: array_unshift version 47

Function:
Description: Pushes elements onto the beginning of the array.
Version:
Status: latest
Date: 2011-12-20 04:37
Summary: Import from phpjs.
Programmer: jj5
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;
}
[top]

Comments

There are no comments yet, be the first!

Please Login or Register to post comments.