I'm trying to select only certain values from my object to write into a file. But this writes the whole object and also unless I use util.inspect it just writes as objects. This should write the values I have chosen from the objects line by line as they come in:
var objectsToFile = function(objectsTotal){
objectsTotal = _.values(objectsTotal, function(value) {
return value.objectTo.employeeName;
});
objectsTotal = _.values(objectsTotal, function(value) {
return value.employeeCurrent;
});
objectsTotal = _.values(objectsTotal, function(value) {
return value.employeePast;
});
writeFile('objectsTotalet.csv', util.inspect(objectsTotal), function(err) {
if (err) console.log(err);
});
};
objectsTotal comes through the function like:
[ { objectTo:
{ employeeName: 'John',
employeeID: '234234',
DOB: '2333'},
employeeCurrent: true,
employeePast: false},
{ objectTo:
{ employeeName: 'Janet',
employeeID: '23423432',
DOB: '23333' },
employeeCurrent:true,
employeePast: false} ]
The output will be conditional which is why I'm using the underscore library but it doesn't work it doesn't even use the returned values from underscore:
There will be other values added to the object so will also need to add a return value like:
objectsTotal = _.values(objectsTotal, function(value) {
return value.employeeStatus != 'employed' ||
value.url.indexOf('employee:') === -1 ||
value.employeeid.length === ('id:')
});
I do need to use this library to give the results I want in a csv file. The output will look like the objectsTotal values returned line by line and can be in one cell.