3

Javascript can read the list using for loop. e.g

 [WebMethod]
    public static List<EmpName> GetData(int startIndex, int maximumRows, string sort, string filter)
    {
        var emp = objClient.GetData(startIndex, maximumRows, sort, filter);
        List<EmpName> lstEmp = new List<EmpName>();
        foreach (var item in emp)
        {
            EmpName objEmp = new EmpName();
            objEmp.ID = item.ID;
            objEmp.Name = item.Name;
            lstEmp.Add(objEmp);
        }
        return lstEmp;
    }

Javascript:
function ReadList(lstEmp)
{
     for(var i=0;i<lstEmp.length;i++)
     {
          alert(lstEmp[i].ID+" "+ lstEmp[i].Name);
     }
}

I want to create a list in javascript i.e List to perform various operation at client side how it can be achieved?

1 Answer 1

3

There are multiple ways to create a List in JS.

The easiest one being

var l = [];
l[0] = "a";
l[1] = 1;

another way todo so is

var l= [1,"as",func];

refer W3Schools

Sign up to request clarification or add additional context in comments.

1 Comment

Actually i was looking for this. var lst = []; lst[0] = [10, 'ABC']; lst[1] = [40, 'DEF']; lst[2] = [70, 'GHI']; for (var k = 0; k <= lst.length - 1; k++) { alert(lst[k][0] + " " + lst[k][1]); } Thanks your code helped me find the soln

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.