I'm currently working on a search functionality where I separate each value in an array, and it's functioning properly. The issue arises when the user enters an empty value, causing the search to break as it returns an empty string within the array collection.
Is there a method to trim or eliminate this empty value?
https://plnkr.co/edit/NXrBtMseWpKrL41K5ojp?p=preview
var idInputValue = document.getElementById("search").value.split('\n');
console.log(idInputValue);
if (idInputValue) {
var ids = idInputValue;
var queryString = "?";
for (var i = 0; i < ids.length; i++) {
var id = ids[i];
if (i > 0) {
queryString += "&";
}
queryString += ("id=" + id);
}
return queryString;
}