javascript - What does [ ] mean in JS? -
i have array below , jquery syntax place data on array table. working fine, but
i don't quite understand keys [ ] mean! such
"<td>" + datelist[i]["name"] + "</td>";
if data isn't array, xml, or json,
"<td>" + datelist[i]["name"] + "</td>";
still working?var datelist =[ { name: "mike jenson", email: "mike_j@yesware.com", phone: "9433550193", joined: "05/23/2014", }, { name: "jim stevens", email: "jim_s@yesware.com", phone: "1299331944", joined: "05/22/2014" }
]; $("#mytable").html(""); (var i=0; i< datelist.length; i++) { var tr="<tr>"; var td1 = "<td>" + datelist[i]["name"] + "</td>"; var td2 = "<td>" + datelist[i]["email"] + "</td>"; var td3 = "<td>" + datelist[i]["phone"] + "</td>"; var td4 = "<td>" + datelist[i]["joined"] + "</td></tr>"; $('#mytable').append(tr+td1+td2+td3+td4); }
[]
used in arrays specify index need access, when say:
somearray[0]
getting value array's first index , in case
specifying index via variable coming loop , in second
specifying object's property property value index passed in 1st []
:
datelist[i]["name"]
in case return ith
index element of array's name property value.
if datelist[0]["name"]
reutrn "mike jenson" because value
of first array object's name property value.
an alterantive datelist[0].name
return same result.
Comments
Post a Comment