WEBVTT 00:06.880 --> 00:10.450 In this video you're going to learn restructuring with objects. 00:10.450 --> 00:19.030 So just like you did with arrays you can also use this structuring with objects by matching values in 00:19.090 --> 00:21.070 different objects. 00:21.130 --> 00:25.700 So let us start by creating an object and call it person. 00:25.850 --> 00:28.090 I'll give it a couple of properties name 00:31.910 --> 00:34.530 and age. 00:34.580 --> 00:36.440 Now if you write something like this 00:48.320 --> 00:54.830 and you set it to person then jealous gives you is going to match the different elements that it finds 00:54.830 --> 00:56.280 inside the objects. 00:56.280 --> 01:04.850 And it's going to identify the new elements which you are declaring in using const and it's going to 01:04.850 --> 01:08.560 set them to the corresponding values inside our objects. 01:08.570 --> 01:12.910 So n is going to be set to join and a you're going to be set to 41. 01:13.050 --> 01:16.520 So you can check that by logging these two values. 01:16.520 --> 01:19.720 And this is what you get. 01:19.930 --> 01:29.740 Now you can also use what we call deep matching meaning that instead of having simple values like buttons 01:30.700 --> 01:39.320 you can actually have object literal structures instead of these values. 01:39.350 --> 01:40.790 So what does it mean. 01:40.790 --> 01:41.960 So let's define 01:44.740 --> 01:46.720 an objects structure like that's 01:50.000 --> 01:59.110 so you've got a property country and we're declaring a variable C and then you've got a property address 02:00.040 --> 02:09.210 instead of declaring a variable a for example or anything else we're going to have an object here and 02:09.490 --> 02:16.570 inside these objects we're going to have a couple of properties postcode which will set B and house 02:16.570 --> 02:20.360 number which will set a variable H. 02:20.360 --> 02:29.110 And now if you said this to other objects where these values are defined 02:37.890 --> 02:40.370 for example then 02:44.120 --> 02:49.020 javascript is going to perform a deep marching between these two elements. 02:49.030 --> 02:57.250 It's going to set C to UK B to the postcode and agent to the house number. 02:57.260 --> 02:58.070 So let's find out 03:06.540 --> 03:07.440 and that's where we get. 03:07.880 --> 03:08.130 All right. 03:08.130 --> 03:12.950 So that's what we call deep marching with E6 restructuring. 03:13.050 --> 03:15.390 Now let's try something else. 03:15.400 --> 03:17.820 So if you write 03:20.600 --> 03:24.290 something like name and age 03:30.310 --> 03:36.500 equal to person in E6 This is exactly the same as writing 03:39.970 --> 03:43.850 name name h h. 03:43.870 --> 03:44.410 All right. 03:44.410 --> 03:50.660 So to simplify things you just write name and age like that. 03:50.780 --> 04:03.790 And now if you log name and age you get the correct volleys thanks to the D factoring all right. 04:04.440 --> 04:05.310 So it is just right. 04:05.340 --> 04:06.660 This is the same as 04:17.050 --> 04:28.010 all right now just like we did with arrays you also can use default values with objects. 04:28.010 --> 04:29.720 So if you do something like 04:40.650 --> 04:54.030 and sets a default value for the country like that's and you say this for example to name objects which 04:54.030 --> 05:02.340 you define right before so it's said these two city New York for example 05:05.080 --> 05:08.760 then if you log 05:11.520 --> 05:17.980 the city and country variables this is what you guys in this scenario. 05:18.120 --> 05:24.570 So the country by default is USA and we've been from within provide the country in this object. 05:24.570 --> 05:32.220 So when you do matching you match City to New York and you don't find a match for countries so you use 05:32.220 --> 05:33.990 the default value. 05:34.030 --> 05:37.860 Now if you specify the country. 05:37.900 --> 05:38.190 Yeah 05:42.170 --> 05:44.840 then that's gonna be different. 05:44.890 --> 05:47.830 I'm not gonna use that body right now. 05:47.930 --> 06:01.420 This is exactly the same as writing city alone and country alone without mentioning the variables. 06:01.500 --> 06:01.730 All right. 06:01.740 --> 06:08.260 So as you know in iOS 5 if you want to do this it's gonna be really laborious. 06:08.260 --> 06:12.710 He will you will need to specify or check the conditions. 06:13.020 --> 06:25.070 So you're gonna check if the objects country is undefined and then you're going to act accordingly. 06:25.330 --> 06:25.580 Right. 06:25.590 --> 06:30.310 Depending on whether the condition is fulfilled or not. 06:30.320 --> 06:30.560 All right. 06:30.560 --> 06:42.360 So now you can use objects restructuring to process return values just like what we did with arrays. 06:42.530 --> 06:52.070 So for example if you define a function process string which takes a string X and returns an object 06:52.520 --> 07:05.210 with a couple of properties value and length then you can simply declare variables like that inside 07:05.210 --> 07:05.850 an object. 07:06.870 --> 07:08.610 So for example value at length. 07:08.610 --> 07:15.060 So again this is the same as writing value call on value and land call on length. 07:15.060 --> 07:30.570 So if you send that to the return of the function and then log the variables value and the length you 07:30.570 --> 07:33.830 get the values that you expect. 07:33.840 --> 07:42.610 All right so this was a quick overview of this structuring with objects in the S6 in the next video 07:42.840 --> 07:45.280 you're going to see these structuring with functions.