I have a custom object that I would like to create an array of. When creating my array it creates an occurrence with empty properties, I understand why, but I would like to avoid this. I realize I could just delete the occurrence with the empty properties, but is there a better way?
function FileToPassBack(path, originalFileName, modifiedDate, newFilename) {
if (!(this instanceof FileToPassBack)) {
return new FileToPassBack(namepath, originalFileName, modifiedDate, newFilename);
}
this.Path = path;
this.OriginalFileName = originalFileName;
this.ModifiedDate = modifiedDate;
this.NewFileName = newFilename;
}
function PostSelectedItems() {
var allFilesToPassBack = new Array(new FileToPassBack());
$('#fileNamesTable').find('tbody>tr:visible')
.each(function (index, element) {
var row = $(this);
if (row.find('input[type="checkbox"]').is(':checked'))
{
var path = row.find('.pathTDClass').html();
var originalFileName = row.find('.originalFileNameTDClass').html();
var modifiedDate = row.find('.modifiedDateTDClass').html();
var newFileName = row.find('input[class="newFileNameTDClass"]').val();
var currentFileToAdd = new FileToPassBack(path, originalFileName, modifiedDate, newFileName)
allFilesToPassBack.push(currentFileToAdd);
}
});
//post path, original file name, modified date, new file name
var objectAsJSON = JSON.stringify(allFilesToPassBack);
}
I am new to JS, so excuse me if I am way off track.