I have an Array
var fieldsToFetch = ['name', 'class', 'rollNumber'];
I am using this array into NODE-ORM2 query, in simple words, I am saying to ORM that this are the fields I want to fetch.
Person.find({ surname: "Doe" }).limit(3).offset(2).only("name", "class", "rollNumber").run(function (err, people) {
// returning only 'name', 'rollNumber' and 'class' properties
//this is working fine
});
In this code, you can see the .only() function which takes the field names. If I am passing the name here by comma separating then it is working fine but if I do like this
Person.find({ surname: "Doe" }).limit(3).offset(2).only(fieldsToFetch).run(function (err, people) {
// returning only 'name', 'class' and 'rollNumber' properties
// not working
});
I also tried
String(fieldsToFetch ); and fieldsToFetch .toString(); but it converts whole array into a single string. So how can I use this array as a parameter here?
Thankyou.
EDIT
Passing 2 or 3 parameter is not a challenge the main goal is to get all array element as individual elements.