我在JavaScript中有以下关联数组结构
Array (
[-1] => Array (
catId : -1
[subCatId] => Array (
subCatId : -3
[0] => Array (
property : value
)
[1] => Array (
property : value
)
)
)
[-4] => Array (
catId : -4
[subCatId] => Array (
subCatId : -6
[0] => Array (
property : value
)
[1] => Array (
property : value
)
)
)
)
我想将其转换为数字数组,就像这样
Array(
[0] => Array(
catID : -1
[subCatId] => Array (
subCatId : -3
[0] => Array (
property : value
)
[1] => Array (
property : value
)
)
)
[1] => Array(
catID : -4
[subCatId] => Array (
subCatId : -3
[0] => Array (
property : value
)
[1] => Array (
property : value
)
)
)
)
我尝试过使用,
var numeric_array = new Array();
for (var items in Array){
numeric_array=Array[items];
}
但它没有达到我要求的结果,我们非常感谢任何建议或意见。
答案 0 :(得分:19)
试试这个:
var numeric_array = new Array();
for (var items in Array){
numeric_array.push( Array[items] );
}
顺便说一下,我不确定Array
对整个数组来说是个好名字:
var hash_array = []; // array which you have
...
var numeric_array = [];
for ( var item in hash_array ){
numeric_array.push( hash_array[ item ] );
}