I have created a CRUD web app based on Googlesheet. I'm getting duplicate search results when I try to search through multiple rows and columns of the html datatable in the web App. This happens when search test matches data in the multiple columns of the same row. How can I get it to display only unique results? How can alter my code to search through only first 3/4 columns?
Example of duplicate search results in the web app search input: test:

Google script code:
function searchData(formObject){
var result = [];
if(formObject.searchtext){//Execute if form passes search text
var data = Sheets.Spreadsheets.Values.get(globalVariables().spreadsheetId, globalVariables().dataRange).values;
for(var i=0;i<data.length;i++){
for(var j=0;j<data[i].length;j++){
if(data[i][j].toLowerCase().search(formObject.searchtext.toLowerCase())!=-1){
result.push(data[i])
}
}
}
}
return result;
}
JavaScript
function handleSearchForm(formObject) {
google.script.run.withSuccessHandler(createTable).searchData(formObject);
document.getElementById("search-form").reset();
}
<!-- SEARCH FORM-->
<form id="search-form" class="form-inline" onsubmit="handleSearchForm(this)">
<div class="form-group mx-sm-3 mb-2">
<label for="searchtext" class="sr-only">Search Text</label>
<input type="search" class="form-control form-control-sm" id="searchtext" name="searchtext" placeholder="Search">
</div>
<button type="submit" class="btn btn-sm btn-primary mb-2">Search</button>
this is the part of the script that searches through all the columns in one row:
for(var j=0;j<data[i].length;j++){ if(data[i][j].toLowerCase().search(formObject.searchtext.toLowerCase())!=-1){ result.push(data[i]) } }
If you would like to search just by, for example, the first column, you could replace that code with:
const COLUMN_INDEX = 0;
if(data[i][COLUMN_INDEX].toLowerCase().search(formObject.searchtext.toLowerCase())!=-1){
result.push(data[i])
}