'AppScript Array Filter (String) not filtering empty values

Trying to filter out empty values from getRange values but still giving me all data. I've tried the following but still not what I expected.

Data array logs the following: 123,,,444,,,331,323,,,,,,5443

var list = source.getRange("sheet!A1:J1:).getValues().filter(String);

or using callback function

list.filter(function(f) {return f[0] !=='';})

Result is still the same 123,,,444,,,331,323,,,,,,5443 What did I missed here?



Solution 1:[1]

After your comment i am not sure if the data you get is an array or an string:

Data array logs the following: 123,,,444,,,331,323,,,,,,5443

For the array case: [123,,,444,,,331,323,,,,,,5443]

const list = [123,,,444,,,331,323,,,,,,5443]
const result = list.filter(Boolean)

console.log(result)

For the string case: 123,,,444,,,331,323,,,,,,5443

const list = '123,,,444,,,331,323,,,,,,5443'
const result = list.split(',').filter(Boolean).map(Number)

console.log(result)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1