How can you get distinct values from a SharePoint List column using JavaScript without a huge performance hit?

A simple example would be appreciated :)

  • How many items you suppose to query? (maximum count) Jan 18, 2012 at 22:16
  • Whats the field type - is it a Choice/MultiChoice (and do you allow 'fill in' values) or something else?
    – Ryan
    Jan 19, 2012 at 8:28
  • At the moment I'm looking at 100+ items, but that could get a lot more over time id recon. In some lists I have choice fields Ryan, other there is People Picker fields Jan 19, 2012 at 11:15

3 Answers 3


Assuming that your field is a Choice/MultiChoice field without "Fill In Choices" enabled then you can use get_choices.

If it does have fill in choices and/or is a different field type then I don't think there is an option apart from brute force (iter over all items getting unique values).


<script type="text/ecmascript">

function GetChoiceValues() {
  var context = new SP.ClientContext.get_current();    
  var web = context.get_web();    

  // Get the list
  var taskList = web.get_lists().getByTitle("list");

  // Get Department choice field (choice field)
  var deptChoiceField = 

  context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod),
                            Function.createDelegate(this, this.onFailureMethod)); 

function onSuccessMethod(sender, args) {
    var choices = deptChoiceField.get_choices();
    alert("Choices: (" + choices.length + ") - " + choices.join(", "));

function onFailureMethod(sender, args) {
    alert("failed. Message:" + args.get_message());


I personally prefer /_vti_bin/listdata.svc. For example to retrieve only Title och Status from 100 first Tasks:

http://dev/_vti_bin/listdata.svc/Tasks()?$select=Title, StatusValue&top=100

See more on my blog: $select, $.getJSON and listdata.svc, updating with listdata.svc

  • i wanna get duplicate list items from the splist, in my SPO, how to retrieve those duplicates?, please help
    – samolpp2
    Apr 27, 2018 at 19:59

I've written this function which will get unique values for a column in SharePoint Online, without having to iterate through each item.

function getUniqueColumnValues(listid, viewid, column,  _callback){
var uniqueVals = [];
    url: _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/filter.aspx?ListId={" + listid + "}&FieldInternalName=" + column + "&ViewId={" + viewid + "}&FilterOnly=1&Filter=1",
    method: "GET",
    headers: { "Accept": "application/json; odata=verbose" }
    }).then(function(response) {
            if ($(b)[0].value) {
    _callback(false,"Error retrieving unique column values");


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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