I want to set the property(p1) of an item in an array. For example, array[1].p1="David". But an error happened. Following is the code, could someone give me a hint?Many thanks.
var array1=new Array();
array1[0].p1="MARY";
array1[1].p1="JHON";
for (index = 0; index < array1.length; ++index) {
alert(array1[index].p1);
}
I`ve tried array1.push({p1:"MARY"}), it works! But it can not set the value by "particular" index.
array1[0] = {p1: "MARY"}.array1[0]does not exist before you insert it, so trying to set itsp1property individually makes no sense.array1[0]has a propertyp1, assuming thatarray1[0]itself is an object?". Was that what you meant?