I would like to remove empty and blank spaces in an array that I get from google sheet and print like this:
var prueba = ['NOV-DIC 17','ENE-FEB 18','MAR-ABR 18','MAY-JUN 18','JUL-AGO
18','SEP-OCT 18','NOV-DIC 18',' ',' ','',''];
As you can see there are both empty and blank spaces after that I format it with a join and it looks like this:
NOV-DIC 17,ENE-FEB 18,MAR-ABR 18,MAY-JUN 18,,,, ,
But what I really need is for me to print this:
NOV-DIC 17,ENE-FEB 18,MAR-ABR 18,MAY-JUN 18
without the last commas
Pick the string after the two commas in a row, it would look like this:
Possibly the easiest way is to use the
filter
object methodArray
to grab the elements that are not made up of only empty spaces:Before printing you can remove them without traversing them or add only the ones with content in a new array, like...
With
Array.filter
it you solve what you want to do