WEBVTT

00:00.430 --> 00:07.720
So now we have the data out in Node JS line by line of each of the data cells in here.

00:07.720 --> 00:12.940
But how can we know which one is the company name and which one is the contact still?

00:12.970 --> 00:16.300
Because we just get them line by line.

00:16.450 --> 00:24.520
So either we have to do something where we divide the index number here by 2 or 3, and we have to take

00:24.520 --> 00:30.490
the modulus of it to find out if it's a company name or contact or country column.

00:31.090 --> 00:37.900
I think it's a little simpler just to take it row by row and say that the first data cell is the company,

00:37.900 --> 00:42.640
the second data cell is the contact, and the third one is the country.

00:42.820 --> 00:44.800
So let's see how we can do that.

00:45.310 --> 00:51.130
And let's try and test it out in the Chrome tools first before we move on to Node JS again.

00:51.460 --> 00:58.060
So inside the Chrome browser, I'm going to press F12 to go back into our console.

00:59.150 --> 01:01.250
So let's take this selector here.

01:01.250 --> 01:07.130
And instead of also taking in the TD, we'll only go to the table row.

01:07.130 --> 01:08.780
So we go like this.

01:11.150 --> 01:13.790
And that's going to get the first table row here.

01:14.060 --> 01:17.120
Now let's take a dot each loop again.

01:17.790 --> 01:19.770
With the index element.

01:22.040 --> 01:29.060
A arrow function and then we can do basically we go through each table row now.

01:29.060 --> 01:37.670
So now we can find the table data cells inside this table row element so we can say something like console

01:37.670 --> 01:38.420
log.

01:39.390 --> 01:47.280
Dollar sign and then take the element and then we can say dot find to find all the children elements

01:48.300 --> 01:50.490
and let's see how that looks.

01:52.240 --> 01:56.800
Now it says it's not a function because I need to have jQuery enabled.

01:57.490 --> 01:58.690
Let's try again.

01:59.020 --> 01:59.860
And there we go.

01:59.860 --> 02:04.900
So now it goes through each row of these table data rows.

02:04.900 --> 02:09.030
So we have here, let me take this away here with the code.

02:09.040 --> 02:17.260
So we have the second row here with three TD cells and the second one, the third row, fourth row,

02:17.590 --> 02:19.120
last row and so on.

02:19.450 --> 02:25.510
So it gets the the, the table data row for each row.

02:26.440 --> 02:31.900
But let's see how we can print out just the first table data cell, the first column.

02:31.900 --> 02:38.410
So in order to do that, we get basically a, we get with find, we get an array back.

02:38.410 --> 02:46.330
If there's of all the children in this table row of a certain class in this case TD So we can try and

02:46.330 --> 02:53.260
just take the first element in this array, which should be the company name for each of these children.

02:53.950 --> 03:01.100
So now when I do that, we can see the first at table row is undefined with the TD because there is

03:01.100 --> 03:03.710
no TD elements in the first row.

03:03.710 --> 03:09.170
It is only a table header class or table header element.

03:09.200 --> 03:17.120
The second one we get the Alfred Frudakis here and balloons, snap curve or whatever you say.

03:17.120 --> 03:23.000
And then we have the the the other ones here all from one column only.

03:23.000 --> 03:28.490
So that's pretty handy because we need to know, okay, which one is the company, which one is the

03:28.490 --> 03:32.090
contact property, Which one is the country property.

03:33.080 --> 03:38.180
So okay, now let's try and transfer this on to NodeJS.

03:38.660 --> 03:41.180
So let's take this code we have here.

03:42.440 --> 03:45.750
And I'm going to paste it inside of NodeJS.

03:45.770 --> 03:48.980
I'm going to overwrite it with the other one we had actually.

03:49.880 --> 03:51.350
So overwrite that.

03:51.350 --> 03:53.530
So now we only go through to our.

03:55.780 --> 04:01.900
And we just print the first element we see in this row.

04:03.410 --> 04:11.150
So let's try and say no, let's save it first and let's say Node index.js see what we get here.

04:11.510 --> 04:18.470
So now we get some weird output inside of the console right now because it's actually printing out or

04:18.470 --> 04:22.610
this element that it's finding is the one we are returning in.

04:22.610 --> 04:30.790
The array is actually a, a chario dom element, so it's printing out the whole Dom object of the index

04:30.800 --> 04:31.580
side, the console.

04:31.580 --> 04:39.410
It's not just the text or the HTML as we see in the Chrome tools, but it's easy to get around.

04:39.410 --> 04:43.040
We just have to use the chario selector again.

04:43.040 --> 04:46.400
So the dollar sign again and then wrap that around here.

04:47.080 --> 04:52.930
And then again in the parent thesis and then say dot text.

04:53.640 --> 04:55.200
So then we take this.

04:55.200 --> 04:58.890
First we have the element, the table row.

04:58.920 --> 05:02.310
We find the table or the table data cells.

05:02.310 --> 05:05.820
The first one we select the first one with the zero index.

05:05.820 --> 05:13.410
And then we take that and surround that with the stereo selector from this Dom element and get the text

05:13.410 --> 05:13.890
from it.

05:13.890 --> 05:21.030
So it's a little confusing because there's so there's a lot of parenthesis going around maybe for some

05:21.030 --> 05:21.930
of you here.

05:21.930 --> 05:25.410
So, but let's see what this outputs.

05:26.960 --> 05:27.780
So there we go.

05:27.800 --> 05:34.160
So now we get all of the table data cells for just the first column with the company name.

05:34.160 --> 05:38.060
So now we easily know that this element right here.

05:38.060 --> 05:38.990
Exactly.

05:38.990 --> 05:40.790
Is the company name.

05:41.030 --> 05:48.110
Okay, So let's try and make the code a little more readable now so we can do something like const DS

05:48.560 --> 05:55.580
equals element, find, find all the children CD elements.

05:55.580 --> 05:58.760
So that's going to make an array of these Dom elements.

05:59.150 --> 06:06.800
And then we can simply say const company equals T DS or actually it's dollar sign.

06:07.950 --> 06:11.100
See DS zero dot text.

06:12.440 --> 06:16.950
Okay, so maybe that's a little easier to read.

06:16.970 --> 06:20.330
Now let's try to do a console log of company name.

06:21.390 --> 06:26.070
Okay, let's try and run Node Index.js and see if it's the same output.

06:26.130 --> 06:28.950
And indeed it is the same output again.

06:29.520 --> 06:39.090
So now we know for sure that we can get all of the company names inside of the inside of this table.

06:39.210 --> 06:43.710
So now we just need to get the other column and it's going to be exactly the same approach.

06:43.740 --> 06:50.070
Again, we just get the one index instead or the two index to get the country.

06:50.670 --> 06:56.890
So now let's look in the next section on how to get the rest of the columns into our data and create

06:56.890 --> 06:59.370
the nice data structure in JavaScript.
