• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/ucode/tests/custom/03_stdlib/66_unshift

  1 The `unshift()` function places the given argument(s) at the begin of the
  2 given array while maintaining their order.
  3 
  4 Returns the last added value.
  5 
  6 Returns `null` if the given destination argment is not an array.
  7 
  8 Throws a type exception if the given array is immuatable.
  9 
 10 -- Testcase --
 11 {%
 12         let arr = [];
 13 
 14         printf("%.J\n", [
 15                 // add one element
 16                 unshift(arr, 123),
 17 
 18                 // add multiple elements
 19                 unshift(arr, 1, 2, 3),
 20 
 21                 // add null values
 22                 unshift(arr, null, null, 4),
 23 
 24                 // no-op
 25                 unshift(arr),
 26 
 27                 // invalid destination
 28                 unshift({}, 1, 2, 3)
 29         ]);
 30 
 31         printf("%.J\n", arr);
 32 %}
 33 -- End --
 34 
 35 -- Expect stdout --
 36 [
 37         123,
 38         3,
 39         4,
 40         null,
 41         null
 42 ]
 43 [
 44         null,
 45         null,
 46         4,
 47         1,
 48         2,
 49         3,
 50         123
 51 ]
 52 -- End --

This page was automatically generated by LXR 0.3.1.  •  OpenWrt