In the select method of SP PnP JS how can I add column names dynamically?

For e.g. can the below code

sp.web.lists.getByTitle("My List").items.select("Col1", "Col2");

be written something like this (this does not work asselect method does not take arrays)?

var cols = ["Col1", "Col2"];
sp.web.lists.getByTitle("My List").items.select(cols);

It supports string array. You need to use the "newer" spread syntax as below:

var cols = ["Col1", "Col2"];
sp.web.lists.getByTitle("My List").items.select(...cols);

Spread syntax in javascript

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.