0

I am scraping some data from a website table using Data Miner. The table has rankings of players in the first column from 1 to 235. The table is split at various locations by a string. I am wanting to remove the rows of the table at these locations to keep the table from being separated. The code below will remove the strings from the column but will leave a blank row. What do I need to add to the code to remove all blank rows from the table? Also, the numbers repeat after 9. What do I need to add to keep the numbers increasing as you move down the table? Below is a link to a picture for some reference.

var cleanup = function(results) {

  $.each(results, function(){  

        var column = this.values[0]; //set column equal to first column of table.

        column = Object.values(column);     // sets column to array.

        var onlyranks = column.filter(value => value.length !== 0);      // set value function to filter column if length does not equal to 0.

         console.log(column);     // display filtered column to console.

  });

  return results;                            // return modified results
};

Picture

New Picture

1 Answers1

0
  1. You can remove empty array object element by this method.

Code:

var array = [
    {Id:1, Name: "kamran"},
    {},
    {}
];
var newArray = array.filter(value => Object.keys(value).length !== 0);

Output:

[
    {Id: 1}
]
  1. You can modify it to remove only strings from array.

Code:

var array = ["a", "b", "", "d", ""];
var newArray = array.filter(value => value.length !== 0);

Output:

["a", "b", "d"]
Premlatha
  • 1,676
  • 2
  • 20
  • 40
  • So I keep getting a .filter and .map "is not a function" error while using both the .filter methods and the .map method. It seems that the error is due to me trying to use an array function on an object or string. I changed the objects to arrays using `column = Object.values(column);`. This split each row into arrays of characters. So rank 1 is ["1"], rank 12 is ["1", "2"] and "Wyndam Rewards" is ["W", "y", "n",...] I've tried filtering out rows with value.length larger than 3 since 235 is max #, I've tried filtering out rows not equal to 0, I've tried filtering out rows by strings and nothing – 0r3d1gger25 Jan 18 '20 at 23:00
  • your "console.log(column)" function is receiving column variable that is not filtered. Pass onlyranks variable to console function and check the output and then let me know. Thanks – Kamran Ahmed Khan Jan 19 '20 at 03:43
  • I'm still getting the same thing. I've uploaded a new picture for reference. – 0r3d1gger25 Jan 19 '20 at 04:37