Array Unshift

From SwiftAPI

Jump to: navigation, search

Inserts a value at the beginning of an array.

For languages that are not shown below, simply use Array Insert with index 0.

Contents

JavaScript

mozilla.org

var a = [6, 8, 10];
a.unshift(2, 4);
// a == [2, 4, 6, 8, 10]

Perl

perldoc

unshift ARRAY,LIST
@a = (6, 8, 10)
unshift(@a, 2, 4)

PHP

php.net

int array_unshift ( array &$array , mixed $var [, mixed $... ] )
$a = array(6, 8, 10);
array_unshift($a, 2, 4);
// $a == array(2, 4, 6, 8, 10)

Ruby

Ruby-Doc.org

array.unshift(obj, ...) -> array
a = [6, 8, 10]
a.unshift(2, 4)
# a == [2, 4, 6, 8, 10]
Personal tools