So if you want them get added to Valid.



if (!filenameRec.next()){ // We are checking here, if recoed doesn't exists


      filenameRec.file_name=filenameArr[i];


      filenameRec.active='true';


      id = filenameRec.insert();


      //valid.push(filenameArr[i]); // valid will have sn.te - Comment this


  }


else


{


          valid.push(filenameArr[i]); // Add values which already exists to Valid variable


}



Please mark this response as correct or helpful if it assisted you with your question.