I am trying to select only certain values from my object for writing to a file. But this writes the whole object, and also, if I do not use util.inspect, it just writes as objects. This should record the values that I selected from the objects in turn when they enter:
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 a 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, so I use the underscore library, but it does not work, it does not even use the return values from the underscore:
Other values will be added to the object, so you also need to add the return value, for example:
objectsTotal = _.values(objectsTotal, function(value) { return value.employeeStatus != 'employed' || value.url.indexOf('employee:') === -1 || value.employeeid.length === ('id:') });
I need to use this library to provide the results that I want in a csv file. The result will look like objects. The returned values are in turn and can be in the same cell.