0

I am retrieving some JSON array from PHP in javascript using ajax. First, I parse JSON array and the access each element using a loop. Now I am stuck on a problem there are some numeric objects in JSON array and I can't access them. My JSON array looks like this:

[
    {
        "Name": "Umar Ghaffar",
        "UniqueID": "b57a956420b885ebb",
        "loggined": "no",
        "Type": "Security",
        "0": "0",    // how can i get the value of this object
        "1": "1"
    },

    {
        "Name": "Usama Ghaffar",
        "UniqueID": "af4dc4ac58ee0eb54",
        "loggined": "",
        "Type": "Security",
        "0": "0",
        "1": "0"
    }
]

This is how I am accessing array

var newText1 = document.createTextNode(data[i].Name);
var newText2 = document.createTextNode(data[i].UniqueID);
var newText3 = document.createTextNode(data[i].loggined);
var newText4 = document.createTextNode(data[i].Type);
var newText5 = document.createTextNode(data[i].0); //here it gives an error
1
  • 1
    data[i]["0"] should do it Commented Mar 8, 2020 at 17:50

1 Answer 1

1

You can try using bracket notation:

 var newText5  = document.createTextNode(data[i]["0"])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.