0
var test = ["", "A Sample PDF.pdf", " ", "file_example_JPG_100kB.jpg", " "]

expected o/p : ["A Sample PDF.pdf","file_example_JPG_100kB.jpg"]

I have tried as :

  1. split by '"' (delimiter as ")

  2. replace spaced strings to empty and then arr.filter(Boolean)

Hope there would an easy understandable way to do this , any help is appreciated

0

2 Answers 2

1

try like this.

var test = ["", "A Sample PDF.pdf", " ", "file_example_JPG_100kB.jpg", " "];

var newT = [];

for(var ind = 0; ind < test.length; ind++){
    if((test[ind].trim()).length > 0){
        newT.push(test[ind]);
    }
}

console.log(newT);

Sign up to request clarification or add additional context in comments.

Comments

1

You can try something like this:

var test = ["", "A Sample PDF.pdf", " ", "file_example_JPG_100kB.jpg", " "]

var filteredData = test.filter(i => {
  return i.replace(/ /g, "").length > 0
})

console.log(filteredData);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.