none
create array from JSON returned from API RRS feed

  • Question

  • I'm using the SharePoint REST API to get data from my list, however, I need to create an array from the one of the columns being returned:

    code:

    $.each(data.d.results, function(index, jCode) {
    	 state = jCode.State;
      });
    
    
    
    

    I the data is:

    CT

    DE

    NJ

    NY,

    is there a way to create an array with it have it like 

    "CT", "DE", "NJ","NY"

    when I try:

    var st = []

    st = state.join(",");

    i get an error: object doesn't support method of join. Is there another way to accomplish this?

    Wednesday, February 15, 2017 3:22 PM

All replies

  • Hi,

    I think you could insert the value to array when you retrieve data.d.results.

    Pseudo code:

    var st=[];

    $.each(data.d.results, function(index, jCode) {

                 state = jCode.State;

                 st.push(state);

      });

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, February 16, 2017 1:43 AM