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 8946305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:28:32+00:00 2026-06-15T12:28:32+00:00

Hi I am fairly new to JavaScript and I am a little confused with

  • 0

Hi I am fairly new to JavaScript and I am a little confused with what to do with an object like the one below. How can I convert this to an array pt where each entry has the properties selid x,y,z?

this is what I see in the Chrome console:
Object {pt[2][y]: "1.3571934700012207", pt[0][selid]: "2", pt[0][z]: "0", pt[3][x]: "3.6684491634368896", pt[2][z]: "0"…}

If I am trying to access pt like in the example below :

var X = pt[2].x;

I get and error “Cannot read property of undefined”. I assume that this is because the object is more like a dictionary with “pt[2][y]” as key and “1.3571934700012207” as value.
However I want to access it like an array pt with objects that have the property x,y,z, selid.
Is there a way to convert/parse the data into the format I want?
Thanks a lot in advance.

  • 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-15T12:28:35+00:00Added an answer on June 15, 2026 at 12:28 pm

    You have say in comment that you do console.log(data) to get obj content. So probably you should do

    var X = data["pt[2][x]"];
    

    If you want to convert it into array pt you should do:

    var data = {
        "pt[0][x]" : 1, 
        "pt[1][x]" : 2, 
        "pt[2][y]" : 3, 
        "pt[2][z]" : 3
    };
    
    var pattern = /^pt\[([^\]]+)\]\[([^\]]+)\]$/i ;
    
    var pt = [];
    for( var key in data ){
    
        if ( pattern.test(key) ){
            var m = key.match(pattern);
            if( !pt[m[1]] ) pt[m[1]] = {};
            pt[m[1]][m[2]] = data[key];
        }
     }
    
    alert(pt[0].x)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First let me preface this question by saying that I'm fairly new to Javascript.
I've been working on a Javascript library, one with basic functionality. I'm fairly new
I'm fairly new to Javascript development so this might be a real newbie question.
Being fairly new to JavaScript, I'm unable to discern when to use each of
This is a very basic question. I'm learning Javascript, and I'm fairly new to
I'm fairly new to javascript and I'm trying to make an form for my
Fairly new to programming. I just can't wrap my head around how to get
I'm fairly new to ruby and I've got a hash that looks like so:
I am fairly new to JavaScript, though not to programming. My exercise is to
I'm fairly new to JavaScript/jQuery/AJAX, so I suspect the issue is some typo I'm

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.