1 00:00:02,210 --> 00:00:09,110 Time for more interesting projections but now projections that work with arrays or are related to arrays. 2 00:00:10,640 --> 00:00:13,370 I'll stick to my friends dataset for this, 3 00:00:13,610 --> 00:00:17,420 so let's quickly peek into it and let's work with the exam scores 4 00:00:17,420 --> 00:00:24,530 now. Let's say you only want to output the first value of that array instead of all the exam scores, 5 00:00:24,590 --> 00:00:27,330 so it's time for a projection of course. 6 00:00:27,440 --> 00:00:30,910 So let's add a project phase here and in projection, 7 00:00:31,110 --> 00:00:40,880 I'm not interested in the ID but I'm very interested in my exam score and I'll name it exam score 8 00:00:40,880 --> 00:00:43,480 and not scores because I'll only output 1. 9 00:00:43,580 --> 00:00:48,530 Now to output one, there is a helpful operator and this is of course the main thing I want to show you here, 10 00:00:48,940 --> 00:00:55,000 the slice operator. The slice operator allows you to get back the slice of an array, 11 00:00:55,400 --> 00:00:57,700 so how does the slice operator work? 12 00:00:57,740 --> 00:00:59,230 It takes an array itself, 13 00:00:59,450 --> 00:01:05,180 the first value is the array you want to slice and you could hardcode an array in here, that would be 14 00:01:05,180 --> 00:01:13,480 possible but of course I will point onto a field with $examscores, 15 00:01:13,520 --> 00:01:19,400 so I'm essentially pointing at this field. And now I only want to get the first element and for this, I 16 00:01:19,400 --> 00:01:27,770 pass one as the second argument because slice takes in its basic form two arguments, the array and the 17 00:01:27,770 --> 00:01:29,780 amount of elements you want to get out of the array 18 00:01:29,810 --> 00:01:31,420 seen from the start. 19 00:01:31,460 --> 00:01:40,550 So here with this, if I take this command and I execute it, you see now I only have my exam score or one 20 00:01:40,970 --> 00:01:46,440 exam score per user and that is the first exam score, we can validate this with the last user, 21 00:01:46,460 --> 00:01:50,440 the first one should be difficulty three and score 75.1 22 00:01:50,630 --> 00:01:53,950 and that is the case here to. Now 23 00:01:53,950 --> 00:02:00,430 sometimes you want to you have let's say the last two, for this you can actually use a negative value 24 00:02:00,430 --> 00:02:03,910 here, -2 because then we'll start at the end, 25 00:02:04,680 --> 00:02:11,490 if I now paste this in, you see I get the last two scores per user, 26 00:02:11,520 --> 00:02:20,620 so this also works or you want to get one element but starting at the second element, then you could 27 00:02:20,620 --> 00:02:24,300 also use a different syntax with three elements in the array, 28 00:02:24,660 --> 00:02:32,500 two and then one. This means start at position two and then give me one element and if I now execute 29 00:02:32,590 --> 00:02:37,550 this, you see I get back some exam scores and which scores added, 30 00:02:37,570 --> 00:02:41,130 well these are the last scores because indexes are zero based, 31 00:02:41,140 --> 00:02:44,860 so if I start at two, I will skip 0 and 1, 32 00:02:44,870 --> 00:02:48,210 so the first two elements, I start at the last element 33 00:02:48,210 --> 00:02:50,300 therefore and then I take one element, 34 00:02:50,320 --> 00:02:53,250 so I get back the last element. 35 00:02:53,290 --> 00:02:58,510 So these are the different ways of using slice and that can be very helpful for transforming an array 36 00:02:58,600 --> 00:03:00,750 or getting just the values of an array 37 00:03:00,790 --> 00:03:01,270 you need.