Go to main content

first

Return first element from array.

FIRST

NAME

first - Return first element from array as a copy.

SYNOPSIS

first(array)

DESCRIPTION

This function return the first element of an array as a copy. The array is not modified

So if a = [1,2,3,4,5]; top(a) return 1 and a has value 1,2,3,4,5.

Function first and top are synonym.

PARAMETERS

array: required, the array to get element from.

RETURN

Returns the first element of an array as a copy.

EXAMPLES

// Basic usage
a = [1,2,3,4,5];
a.top();
// result 1
a;
// result [1,2,3,4,5]

// First item as a copy
people = [{"name": "Luke"}, {"name": "John"}];
user1 = people.first(); // Creates a copy of the first element
user1;
// Result {"name":"Luke"}
user1.name = "Lanny";
user1.job = "carpenter";
people; // Unmodified original array
// Result [{"name":"Luke"},{"name":"John"}]

 

 

SEE ALSO

{{ include("includes/array.sn") }}

AUTHOR

Written by Pierre Laplante, <laplante@sednove.com>

MODIFICATIONS

1.0 2014-09-09 21:24:14 laplante@sednove.com

Edit

© 2024 extenso Inc. All rights reserved.