Is there some kind of loop in Javascript that's equivalent to the foreach() loop in PHP???
PHP Code:
foreach ( $AREA as $AreadID => $AreaName) {
// do something //
}
Printable View
Is there some kind of loop in Javascript that's equivalent to the foreach() loop in PHP???
PHP Code:
foreach ( $AREA as $AreadID => $AreaName) {
// do something //
}
I don't recall how to do it. In JavaScript, I'm not sure that one can have arrays with indices other than incrementing numbers; I would say no, but that is just a guess.
I don't think I understand what you mean...?
What is the code you gave me supposed to do? and how can it help me, in my case?
PHP can have different keys or indices for each element. Terefore, you could something like: $arr['car'];, if you defined in your array "car" => "Honda" .
For a JS solution, see below.
well thanks anyway...
I'm sure this will help me some time in the future... :)
well... you can indeed have arrays with associative indices in javascript, means not only numbers. you can even have multi-dimensional arrays...
well and for the foreach...Code:<script type="text/javascript">
var aCharts = new Array();
aCharts['classes'] = new Array( 'notselected', 'selected' );
aCharts['base_url'] = '***************';
aCharts['images'] = new Array();
aCharts['images'][0] = '1D';
aCharts['images'][1] = '3M';
aCharts['images'][2] = '6M';
aCharts['images'][3] = '1Y';
aCharts['images'][4] = '3Y';
</script>
you have to use a for loop in this way:
To see the whole thing in action i'm attaching a sample file with just dumps the aCharts array.Code:for( var sIndex in aArray ) {
var sValue = aArray[sIndex];
....
}
Gee...
Thanks for the examples and explanations!!!
:)