开发者

How to create a list in javascript

开发者 https://www.devze.com 2023-02-27 02:47 出处:网络
Javascript can read the list using for loop. e.g [WebMethod] public static List<EmpName> GetData(int startIndex, int maximumRows, string sort, string filter)

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, maximum开发者_高级运维Rows, 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消