Jump to content

how to loop through an array of unknown size


christys

Recommended Posts

Hi,

I trying to write a code for iterating through the array.

Array size will be dynamic, that means we don't know how many elements are there internally.

So how can I create an array without size.

And my array will be a string.

 

var membernames=new Array();

Can I initialize this way?

I want to loop through a set of elements whose size is unknown and retrieve all those details into a variable.

How can I do this? Please let me know..

 

Thanks

Edited by christys
Link to comment
Share on other sites

that's PHP.

 

 

 

Hi,

I trying to write a code for iterating through the array.

Array size will be dynamic, that means we don't know how many elements are there internally.

So how can I create an array without size.

And my array will be a string.

 

var membernames=new Array();

Can I initialize this way?

I want to loop through a set of elements whose size is unknown and retrieve all those details into a variable.

How can I do this? Please let me know..

 

Thanks

 

I'm not sure what you're asking. Do you want to know how to iterate through an unspecified array size at runtime? If so, you can use push to add to an array, and use the length property to use as the ending conditional for a for loop.

 

You can find this info in the Array references sections

http://www.w3schools.com/js/js_arrays.asp

http://www.w3schools.com/jsref/jsref_obj_array.asp

Link to comment
Share on other sites

All arrays in Javascript have a length property which indicates how many elements they contain. If it doesn't have a length property then it's not an array.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...