In jQuery, there are multiple parameters in a list. We can add these parameters in a jQuery ArrayList. For that, first we have to make an array list object and then the value will be pushed in this list.
Array in jQuery
Declare Array
The above code has created an empty array.
Assigning valus at the time of declaration in Array
- var fruits = ["Banana", "Orange", "Apple", "Mango"];
- var number=["1","2","3","4"];
The above code has created an array with assigned values.
ArrayList in jQuery
ArrayList is used when we want to add multiple values of multiple types in an array.
- DataList.push({
- Id:1,
- Name: ABC
- });
- DataList.push({
- Id:2,
- Name:ABC
- });
The above code has created "DataList" as an ArrayList with multiple parameters.
Explanation
Id=1, name="ABC" has 0 Index.
Id =2 ,name="ABC" has 1 Index
Assigning values at the time of declaration in ArrayList
- DataList=[{
- Id:1,
- Name:ABC
- }
- {Id:2,
- Name:XYZ
- }];
Explanation
Id=1,Name="ABC" is in 0 index
Id=2,Name="XYZ" is in 1 index
Assigning values in ArrayList using for Loop
The loop starts from 0 index and goes up to the length of the DataList. We are assigning the values of the Ids to Id parameter and naming to the naming parameter.
- var Ids=1;
- var naming="ABC";
- for(var i=0;i<DataList.length;i++)
- {
- Ids=DataList[i].Id;
- naming=DataList[i].Name;
- }
While accessing DataList, we will use the following.
DataList[i].Id
i is the Index of the DataList.
DataList[0].Id=1
DataList[0].Name=ABC
Output
1
ABC