1

I have an array which I declared as var myclinicsID = new Array(); and now, I push some data in it,when I alert it using alert(JSON.stringify(myclinicsID)) it gives me output of ["1","2","3","4"]

Now I want to use this for my function and when I look at in console, it gives me undefined, am I doing correct by my code :

getbarSeriesData(myclinicsID[0]['clinic_id'],data[i]['datemonths']);

I want to get myclinicsID first data element which is the value is 1

1
  • You don't have anything by clinic_id in the array Commented Apr 25, 2017 at 3:46

2 Answers 2

2
myclinicsID[0]['clinic_id']

Should be

myclinicsID[0]

All you need the array index. When you say myclinicsID[0]['clinic_id'], that is trying to get the clinic_id property of "1" which is obvious undefined.

Sign up to request clarification or add additional context in comments.

4 Comments

hello sir, since it was easy for you. can i ask another regardng with array?
@JcJohn You can ask.
opps hello sir can we discuss something? @ANS
for (var i in data) { categories.push(data[i]["datemonths"]); var innerLoop = 0 for(var i in data) { getbarSeriesData(myclinicsID[0],data[i]['datemonths']); innerLoop++; } } i have two loops and in my second loop, i want the length of my array to be the end of looping before going back to the outer loop
2

Why myclinicsID[0]['clinic_id'] ? As there is nothing like clinic_id in your array.

Your array is single dimensional array. Hence, you can directly access the first element from an array using myclinicsID[0].

DEMO

var myclinicsID = new Array();
myclinicsID[0] = 1;
myclinicsID[1] = 2;
myclinicsID[2] = 3;
myclinicsID[3] = 4;

function getbarSeriesData(clientID) {
  console.log(clientID);
  alert(clientID);
}

getbarSeriesData(myclinicsID[0]);

6 Comments

hello @Rohit, i have another question can you help me?
hello. why is this not working ? alert(myclinicsID[0]);
alert(myclinicsID[0]) is working fine. I updated my answer you can check now.
getbarSeriesData(myclinicsID[0],data[i]['datemonths']); , in my console i got POST XHR localhost/clinic/patients_report/get_checkup/March/undefined
why mine says undefine?
|

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.