I have done a data merge on indd file with CSV data source.
myDocument.dataMergeProperties.selectDataSource(new File ('E:/Employees.csv'));
I need to loop through data source for some conditional logic. If, somehow, we can save this data source in local variable [array].
You can read the source file and do some splitting based on the separator used. But if you need to go crazy with conditions, you may envision dedicated tools such as EasyCatalog.
Actually, I am not aware about scripting property/method required to perform this operation. Any sample script.