Missing one important component here. I'm making a REST call with jQuery ajax, and would like to know how to run my if statement for all items or the current active item [this] instead of just the first value in the array that returns to me. See code below:

   url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('My List')/items?$select=Field",
   type: "GET",
   headers: { "ACCEPT": "application/json;odata=verbose"},
   success: function (data){
       $.each(data, function(){
          var field = data.d.results;
     if (**field[0]**.DocLink.Description.length > 0){
     else alert("proof")'

**Code works if I use bracket notation to select first object in array, comes back undefined without it.


Check out the proper syntax of the jQuery.each() function.

$.each() expects two parameters: the first is the array that you're looping through, and the second is a callback function to execute for every element of the array.

So when you have an array stored in the variable data.d.results, you can loop through each of the items in the array by doing something like this:

$.each(data.d.results, function(index,item){ 
    //do something with the item value here

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.