I have an array cornerId inside an object elementMatrix. Thereafter I want to create elemArray which is an array of the object elementMatrix. However I am not able to access the value of cornerId.
function elementMatrix() {
var cornerId=new Array();
}
var elemArray=new Array();
elemArray[0]=new elementMatrix();
elemArray[0].cornerId[0]="z"; //if I put elemArray[0].cornerId="z"; then it works for the first element - but then how do I put second element???
elemArray[0].cornerId[1]="a";
alert(elemArray[0].cornerId[0]); // shows undefined
alert(elemArray[0].cornerId[1]); //again undefined
....
Add other elemArray values
....
I want to assign values and access values for the nth position of the array cornerId, which is a part of elemArray which is an array of object elementMatrix. Can anyone show me the right way to access cornerId values???
EDIT:
To clarify I want the liberty to add cornerId at the nth position (overwrite existing value) and not push it. Also I had not asked this originally but if there is a method to remove an nth position from cornerId then that will be great.
define your corner with this, push on arrays…. like this
or you can make your cornerid private and return public method like this (add is fluent)
edit, if you want a key value pair use a object instead a array like this