WEBVTT

00:00.560 --> 00:01.340
Okay, one.

00:01.340 --> 00:06.320
So right now we have the job description that we can select and print out.

00:06.530 --> 00:07.910
We also have the job title.

00:08.360 --> 00:10.160
We can select it and print it out.

00:10.520 --> 00:16.430
But remember before in the other section about data structure, I talked about that we wanted to have

00:16.430 --> 00:18.050
an array of objects.

00:19.090 --> 00:20.530
So let's look at about.

00:20.590 --> 00:26.740
So let's look on how to get this array of objects and we'll return that.

00:27.310 --> 00:35.370
So instead of doing two dot each loops, we're going to just do one dot map loop instead.

00:35.380 --> 00:40.690
And this dot map loop is going to return the array of objects with all the different properties.

00:41.530 --> 00:48.370
So I can go ahead and test out, write some code, then I can paste it inside the Chrome developer console

00:48.400 --> 00:54.670
to test out if it works in a fast and easy way compared to running the chromium browser first.

00:55.880 --> 00:57.770
So let's see how we can do this.

00:58.370 --> 01:05.120
Remember that the result of the job title and the job URL is inside the same element.

01:05.120 --> 01:10.970
So we're just going to do one loop and get two properties in one, two for one.

01:11.330 --> 01:16.550
So result title and then we're going to use a dot map instead.

01:17.290 --> 01:21.070
And it has the same arguments, the index and the element.

01:21.610 --> 01:27.430
And then we use a curly brace here because we're going to do a little magic here.

01:28.330 --> 01:30.160
We're going to say const.

01:30.980 --> 01:38.600
And title and well, when I say we're going to do a little magic here, I mean that we're going to do

01:38.630 --> 01:45.080
multiple statements rather than just return one statement, then you can omit the curly braces.

01:45.080 --> 01:51.800
But since we're going to do several things inside the function, we need to use the curly braces.

01:51.800 --> 01:55.400
So a little further explanation than just saying magic.

01:55.670 --> 02:02.060
Anyway, then we say the jQuery selector dot text to get the title.

02:02.970 --> 02:04.710
And URL is.

02:05.130 --> 02:07.960
Element attribute href.

02:08.010 --> 02:09.840
We already done that before.

02:10.230 --> 02:14.010
Now we just need to return a new object.

02:14.010 --> 02:21.330
So we say return and then have the curly braces for returning a JavaScript object.

02:21.550 --> 02:27.090
Then we put in a title the property of the title and then the URL.

02:28.100 --> 02:30.580
That's going to return an array of objects.

02:31.590 --> 02:39.000
Let's also make sure that we have this const results array that we're returning here from this dot map

02:39.000 --> 02:39.780
function.

02:40.520 --> 02:45.620
So that's going to return this array of objects with the different properties.

02:46.440 --> 02:53.070
So let's say console log results just to check if we got all of the elements.

02:53.970 --> 02:57.810
Now, since I just want to check quickly.

02:57.810 --> 03:06.420
If it works, I can put it inside the Chrome developer console just to check if my code works very fast

03:06.630 --> 03:11.970
and I can see I get an array of different objects and if I look inside it.

03:13.060 --> 03:19.300
I can see that number zero has a title and a URL, so it all looks good.

03:19.300 --> 03:25.420
And now we're going to run it inside the NodeJS project and see if it works.

03:25.420 --> 03:27.460
So Node Index.js.

03:30.840 --> 03:33.510
Now the page has loaded and.

03:34.560 --> 03:38.880
I can see lots of console printouts and something else.

03:39.030 --> 03:45.600
So I'm just going to delete the old each loops we have before because we're not going to use them anymore.

03:45.630 --> 03:46.440
They're just.

03:48.000 --> 03:49.560
Uh, not being used now.

03:50.320 --> 03:52.780
We're only going to do one loop instead.

03:53.350 --> 03:58.270
So let's close the browser here and then let's run it again.

03:59.720 --> 04:05.420
And this is why I like to test things out inside Chrome developer console, because you can just test

04:05.420 --> 04:10.520
it out really fast in the console compared to when it has to load out the browser first.

04:11.750 --> 04:12.650
Anyway.

04:13.010 --> 04:21.110
Now, as you can see, it's returning this weird output with some something about root and objects and

04:21.110 --> 04:21.740
circular.

04:21.770 --> 04:23.900
Lots of interesting things.

04:24.050 --> 04:29.840
And what is what is actually returning is an array of different cherry objects.

04:31.630 --> 04:39.130
There is one difference between Cheerio and jQuery, which always gets me for some reason, which is

04:39.130 --> 04:42.130
that you have to use a dot get.

04:42.490 --> 04:46.810
When you use a dot map function inside of NodeJS you.

04:47.580 --> 04:51.750
Compared to when you're inside jQuery, inside the browser.

04:51.750 --> 04:53.010
You don't have to do that.

04:53.040 --> 04:56.400
You can simply get away with just doing something like this.

04:56.820 --> 05:02.940
But if you're inside Node JS, which aerial, you have to make sure to have a dot get when you're using

05:02.940 --> 05:04.110
a map function.

05:04.500 --> 05:08.040
Then you're going to get the values of the actual array.

05:08.160 --> 05:15.210
And now if I run it inside the console again or inside Node JS again, I can see that we should be getting

05:15.210 --> 05:21.300
the values of the different objects instead instead of these chario objects.

05:22.140 --> 05:23.310
So there we go.

05:23.310 --> 05:28.700
Now I'm getting all of the titles and URLs in this array instead.

05:28.710 --> 05:33.850
And now we're absolutely sure that each title and URL fits one another.

05:33.870 --> 05:37.380
There hasn't been any skips in the loops or something like that.

05:38.400 --> 05:39.900
So now on to the next section.

05:39.900 --> 05:46.470
We're going to get some more properties into our array and find the date the job was posted.
