Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9008207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:53:18+00:00 2026-06-16T01:53:18+00:00

I have an array cornerId inside an object elementMatrix . Thereafter I want to

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:53:19+00:00Added an answer on June 16, 2026 at 1:53 am

    define your corner with this, push on arrays…. like this

    function elementMatrix() {
        this.cornerId = [];
    };
    var elemArray = [];
    var newMatrix =new elementMatrix();
    newMatrix.cornerId.push('z');
    newMatrix.cornerId.push('a');
    elemArray.push(newMatrix);
    
    alert(elemArray[0].cornerId[0]);
    alert(elemArray[0].cornerId[1]);
    

    or you can make your cornerid private and return public method like this (add is fluent)

    function elementMatrix() {
        var cornerId = [];
    
        return {
            addCornerId: function(id) {
                cornerId.push(id);
                return this;
            },
    
            getCornerId: function(pos) {
                if(cornerId.length >= pos) {
                    return cornerId[pos];
                }
    
                return null;
            }
        };
    };
    var elemArray = [];
    var newMatrix =new elementMatrix();
    newMatrix
        .addCornerId('z')
        .addCornerId('a');
    elemArray.push(newMatrix);
    
    alert(elemArray[0].getCornerId(0));
    alert(elemArray[0].getCornerId(1));
    

    edit, if you want a key value pair use a object instead a array like this

    function elementMatrix() {
        var cornerId = {};
        var nextKey = 0;
    
        return {
            addCornerId: function(id, key) {
                if(!key && key !== 0) {
                    key = nextKey;
                }
                cornerId[key] = id;
                nextKey++;
                return this;
            },
    
            removeCornerId: function(key) {
                if(cornerId[key]) {
                      delete cornerId[key]
                }
    
                return this;
            },
            getCornerId: function(key) {
                if(cornerId[key]) {
                    return cornerId[key];
                }
    
                return null;
            }
        };
    };
    var elemArray = [];
    var newMatrix =new elementMatrix();
    newMatrix
        .addCornerId('z')
        .addCornerId('a')
        .addCornerId('XXX', 0)
        .addCornerId('YYYY', 'abc');
    elemArray.push(newMatrix);
    
    alert(elemArray[0].getCornerId(0));
    alert(elemArray[0].getCornerId('abc'));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have array of objects with created images (Object.Image), i want to show images
I have array with colors as its objects. I want to create an image
I have array d, I want array d2 The rows do not have the
I have an array that is a object which I carry in session lifeFleetSelectedTrucksList
I have array like below the page. I want to find array number which
I have array result like this: Array ( [0] => stdClass Object ( [id_global_info]
I have array in json, but I want to print it in php. I
I have array that element is hash a = [{:history_date=>15/07/10}, {:open_price=>7.90}] I want to
I have array data as shown below, I want to store 'sale' value into
Now I have Array(1 => Array(aaa,bbb,ccc)) Array(2 => Array(eee,fff,ggg,hhh)) And I want to make

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.