Ruby program to get the first N items from the array using the take() method

bookmark

arr = [100,101,102,103,104];
items = arr.take(2);

print "Array: ",arr,"\n";
print "First 2 items: ",items,"\n";

 


Output:

Array: [100, 101, 102, 103, 104]
First 2 items: [100, 101]