[英]Convert associative array to numeric array
I have the following associative array structure in JavaScript 我在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
)
)
)
)
I want to convert this into numeric Array, like this 我想将其转换为数字数组,就像这样
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
)
)
)
)
I have tried using, 我试过用,
var numeric_array = new Array();
for (var items in Array){
numeric_array=Array[items];
}
but its not achieving my required result, any suggestions or comments are greatly appreciated. 但它没有达到我要求的结果,任何建议或意见都非常感谢。
try this: 试试这个:
var numeric_array = new Array();
for (var items in Array){
numeric_array.push( Array[items] );
}
btw, I'm not sure Array
is good name for you entire array: 顺便说一句,我不确定Array
是否适合整个数组:
var hash_array = []; // array which you have
...
var numeric_array = [];
for ( var item in hash_array ){
numeric_array.push( hash_array[ item ] );
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.