1
00:00:00,650 --> 00:00:06,380
Right in the last video we took a look at maps which are a new object structure in Essex and I wanted

2
00:00:06,380 --> 00:00:07,950
to take a look at sets.

3
00:00:07,980 --> 00:00:14,570
OK so sets are basically unique values.

4
00:00:14,580 --> 00:00:20,020
It's a list of a set of unique values of any type whether it's primitive or reference.

5
00:00:20,190 --> 00:00:21,690
OK and they're always unique.

6
00:00:21,690 --> 00:00:33,300
So you can't have the same one twice so let me just put in here or say store unique values of any type.

7
00:00:33,300 --> 00:00:33,630
All right.

8
00:00:33,630 --> 00:00:36,920
So we're going to create a variable called Set One.

9
00:00:36,960 --> 00:00:41,310
Set it to a new set.

10
00:00:41,820 --> 00:00:43,860
OK.

11
00:00:44,010 --> 00:00:54,210
Actually it's put parentheses there and we want to add some values or say add values to the set.

12
00:00:54,240 --> 00:01:01,230
And we can do that using the add method so we can say set one Daut add and let's add a number.

13
00:01:01,230 --> 00:01:03,120
So I'll say 100.

14
00:01:03,240 --> 00:01:10,290
All right then we'll do set one dot and let's add a string we'll say a string

15
00:01:13,500 --> 00:01:18,730
is one dot and let's add an object.

16
00:01:18,730 --> 00:01:22,160
So will say name John

17
00:01:26,230 --> 00:01:29,380
to add and we'll do a boolean.

18
00:01:30,310 --> 00:01:34,860
OK so we have all of these different types in our set.

19
00:01:34,870 --> 00:01:36,640
All right so let's console log

20
00:01:40,560 --> 00:01:41,920
set 1.

21
00:01:42,480 --> 00:01:47,960
Ok so you can see that it actually tells us it's a set and it has four different values in it.

22
00:01:48,150 --> 00:01:53,820
And if we look we have our number our string or object and our boolean.

23
00:01:53,820 --> 00:01:55,470
Now if I were to try to add

24
00:01:58,380 --> 00:02:09,420
100 again which is already there and save notice we still only have four four things in the set and

25
00:02:09,420 --> 00:02:11,790
it didn't add it again because it's already there.

26
00:02:11,790 --> 00:02:19,100
So that's that's what's great about sets is that we have to be unique values.

27
00:02:19,140 --> 00:02:19,520
OK.

28
00:02:19,530 --> 00:02:28,530
Now if you don't want to add things this way I'll just leave that you could create a set to set to and

29
00:02:28,530 --> 00:02:32,570
you could say new set and you could pass.

30
00:02:32,580 --> 00:02:39,090
And here basically an array of different things that say one true

31
00:02:41,460 --> 00:02:52,170
string and we could say console log set to and save and you can see we have another set so you can use

32
00:02:52,170 --> 00:02:55,500
this format or this format.

33
00:02:55,500 --> 00:02:59,970
All right we're going to stick to set one for testing and stuff.

34
00:03:00,060 --> 00:03:05,310
Let's see if we can also get the size or the count by saying

35
00:03:09,660 --> 00:03:18,200
Just like with maps we use the Size property so that tells us that this for now we can also check for

36
00:03:18,200 --> 00:03:21,400
values.

37
00:03:22,100 --> 00:03:30,230
So let's say Konsole door log set one and we can use Dot has for this.

38
00:03:30,250 --> 00:03:34,130
So I will say has one hundred and save and we get true.

39
00:03:34,630 --> 00:03:35,950
All right.

40
00:03:36,140 --> 00:03:37,790
Now we could even do

41
00:03:40,670 --> 00:03:48,650
we could even do has and then do an expression that equals 100 like 50 plus 50 and save.

42
00:03:48,650 --> 00:03:50,840
And again we get true.

43
00:03:50,840 --> 00:04:02,180
Now one thing that you may be surprised by is that if we put an object in here and say name John and

44
00:04:02,180 --> 00:04:08,870
say we get false OK if you look up here we do have an object that has named John you can see it even

45
00:04:08,870 --> 00:04:12,010
highlights at the same time it's the exact same characters.

46
00:04:12,050 --> 00:04:19,410
But if you remember back to data types this is a reference object this is not.

47
00:04:19,580 --> 00:04:26,270
This is not a primitive value that's actually stored in in the stack.

48
00:04:26,310 --> 00:04:31,480
Ok it's stored in the heat which which makes it a reference value.

49
00:04:31,490 --> 00:04:41,510
So even if we were to say if we were to copy this right here and say Konsole door log and say this object

50
00:04:42,200 --> 00:04:47,620
is equal to the same exact thing same object and say we're going to get false.

51
00:04:47,690 --> 00:04:53,570
OK because it's not it's just it's it's pointing to a different location in memory.

52
00:04:53,600 --> 00:04:55,220
It's not a primitive type.

53
00:04:55,340 --> 00:04:58,560
Like a number or a string or a boolean.

54
00:04:58,940 --> 00:05:09,860
If we were to say the string hello is equal to the string hello then we get true OK because a string

55
00:05:09,860 --> 00:05:13,000
is a primitive value so hopefully that makes sense.

56
00:05:13,070 --> 00:05:18,600
But that's why we get false when we try when we try to check for this.

57
00:05:18,640 --> 00:05:22,210
All right another thing we can do is delete from the set.

58
00:05:23,690 --> 00:05:38,620
OK so if we say set one dot delete and I'll pass in one hundred and then console log set or set one

59
00:05:38,920 --> 00:05:39,550
and save.

60
00:05:39,550 --> 00:05:42,940
You can see now we only have three in there and 100 is not there.

61
00:05:42,940 --> 00:05:45,890
We can delete it using the delete method.

62
00:05:46,510 --> 00:05:54,280
OK so we can also iterate through sets.

63
00:05:54,590 --> 00:06:00,350
So let's go ahead and say actually let's do a four.

64
00:06:00,560 --> 00:06:03,320
We'll do a 4 of

65
00:06:07,200 --> 00:06:08,180
you know do for us.

66
00:06:08,180 --> 00:06:13,540
So say four and we'll pass in here.

67
00:06:16,310 --> 00:06:20,160
Lead item of set one.

68
00:06:20,240 --> 00:06:20,530
All right.

69
00:06:20,540 --> 00:06:23,050
And then we'll just Konsole dot Warg

70
00:06:25,560 --> 00:06:27,740
item and save.

71
00:06:27,930 --> 00:06:34,700
And this is probably going to confuse you guys because we have so many console logs so let me just comment.

72
00:06:34,780 --> 00:06:35,150
So

73
00:06:38,980 --> 00:06:41,680
so save that and this is what we're getting.

74
00:06:41,680 --> 00:06:47,470
So we're looping through using maybe we're getting a string we're getting the object in the true value

75
00:06:47,770 --> 00:06:50,890
the 100 isn't showing up because we still have this delete.

76
00:06:50,890 --> 00:06:56,000
Here if I get rid of that and save then that 100 is going to show up.

77
00:06:56,600 --> 00:07:03,020
Now sets are not key value pairs they're just single value so we could actually do either.

78
00:07:03,040 --> 00:07:07,390
We could do Daut values like that and we're going to get the same thing.

79
00:07:07,510 --> 00:07:16,330
We can do dog KIIS get the same thing and we can do Daut entries and get the same thing actually entries

80
00:07:16,450 --> 00:07:17,530
is a little different.

81
00:07:17,530 --> 00:07:20,320
We're going to get an array.

82
00:07:20,630 --> 00:07:27,670
Actually I've never done entries so I guess we get an array with two.

83
00:07:27,670 --> 00:07:29,480
So that's kind of strange.

84
00:07:29,740 --> 00:07:35,490
I don't think that you would actually use that in many cases but it is possible.

85
00:07:35,500 --> 00:07:39,170
All right so just get rid of that.

86
00:07:39,850 --> 00:07:43,730
All right so we can also use a For Each loop

87
00:07:48,170 --> 00:07:58,340
ok so if we were to say set one dot for each and pass it a function we could pass in an arrow function

88
00:08:01,550 --> 00:08:13,280
and say value Konsole dot log value and save and you could see it's looping through those values.

89
00:08:13,340 --> 00:08:13,620
All right.

90
00:08:13,630 --> 00:08:19,340
And just with just like with maps we can convert sets into arrays.

91
00:08:23,860 --> 00:08:38,080
So for that let's do current set array and we'll set that to array dog from and set 1 and let's say

92
00:08:38,080 --> 00:08:43,320
console dot log set the array and save.

93
00:08:43,330 --> 00:08:47,190
And now we have an array of the things that are in our set.

94
00:08:47,200 --> 00:08:47,500
All right.

95
00:08:47,500 --> 00:08:53,710
So just another option another object structure that we can use now with iOS 6 plus.

96
00:08:54,010 --> 00:08:58,540
Hopefully this helped you guys out help you understand what a map in a set is.

97
00:08:58,570 --> 00:09:01,860
So that's it guys and I will see you in the next video.

