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

  • Home
  • SEARCH
  • 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 651149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:07:53+00:00 2026-05-13T22:07:53+00:00

I am converting a look-up table in PHP which looks like this to JavaScript

  • 0

I am converting a look-up table in PHP which looks like this to JavaScript using json_encode:

 AbilitiesLookup Object
(
[abilities:private] => Array
    (
        [1] => Ability_MeleeAttack Object
            (
                [abilityid:protected] => 
                [range:protected] => 1
                [name:protected] => MeleeAttack
                [ability_identifier:protected] => MeleeAttack
                [aoe_row:protected] => 1
                [aoe_col:protected] => 1
                [aoe_shape:protected] => 
                [cooldown:protected] => 0
                [focusCost:protected] => 0
                [possibleFactions:protected] => 2
                [abilityDesc:protected] => Basic Attack
            )
            .....snipped...

And in JSON, it is:

{"1":{"name":"MeleeAttack","fof":"2","range":"1","aoe":[null,"1","1"],"fp":"0","image":"dummy.jpg"},....

The problem is I get a JS object, not an array, and the identifier is a number. I see 2 ways around this problem – either find a way to access the JSON using a number (which I do not know how) or make it such that json_encode (or some other custom encoding functions) can give a JavaScript associative array.

(Yes, I am rather lacking in my JavaScript department).

Note: The JSON output doesn’t match the array – this is because I do a manual json encoding for each element in the subscript, before pushing it onto an array (with the index as the key), then using json_encode on it. To be clear, the number are not sequential because it’s an associative array (which is why the JSON output is not an array).

  • 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-05-13T22:07:53+00:00Added an answer on May 13, 2026 at 10:07 pm

    JavaScript object property names can be strings in any format. They can even be just digits (as it is in your case) and there’s no issue with accessing them with numeric indexes/keys:

    var obj = {
        "1": "foo",
        "2": "bar"
    };
    
    obj["1"]; // returns "foo"
    obj[1]; // returns "foo" (1 will implicitly get cast to the string "1")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 533k
  • Answers 533k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The primary keys for the event_person tables are not equivalent… May 17, 2026 at 12:24 am
  • Editorial Team
    Editorial Team added an answer There's a big difference between "equal to" and "pointer to… May 17, 2026 at 12:24 am
  • Editorial Team
    Editorial Team added an answer We're solving this with a HomepageController that renders two different… May 17, 2026 at 12:24 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Hey guys, take a look at this, maybe you can help me. This code
I have an object, and before I serialize it to Json, I'd like to
I want to start by saying that I am a big fan of using
Is there an efficient method of converting an integer into the written numbers, for
So you have Table mapping the 26 ascii characters from the English alphabet to
I'm using the ancestry gem to help organise my app's tree structure in the
Can/Should I use a LIKE criteria as part of an INNER JOIN when building
I am trying to create a table with two groups in a BIRT report.
Converting numbers to strings is no problem, but the string created uses ascii numbers.
Converting a database of people and addresses from ALL CAPS to Title Case will

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.