함수 shift()

(함수 array shift()에서 넘어옴)


1 JavaScript[ | ]

var fruits = ["Banana", "Orange", "Apple", "Mango"];
var fruit = fruits.shift();
console.log(fruit);
// Banana
console.log(fruits);
// Array[3]
// 0: "Orange"
// 1: "Apple"
// 2: "Mango"

2 PHP[ | ]

$fruits = array("Banana", "Orange", "Apple", "Mango");
$first = array_shift( $fruits );
print_r( $first );
// Banana
print_r( $fruits );
# Array
# (
#     [0] => Orange
#     [1] => Apple
#     [2] => Mango
# )

3 Perl[ | ]

my @arr = ("Banana", "Orange", "Apple", "Mango");
my $first = shift @arr;
print $first . "\n";
# Banana
print @arr;
# OrangeAppleMango

4 Python[ | ]

fruits = ['Banana', 'Orange', 'Apple', 'Mango']
first = fruits[0]
fruits = fruits[1:]
print( first )
# Banana
print( fruits )
# ['Orange', 'Apple', 'Mango']

5 Ruby[ | ]

arr = ["Banana", "Orange", "Apple", "Mango"]
first = arr.shift
puts first
# Banana
puts arr
# Orange
# Apple
# Mango

6 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}