繁体   English   中英

改变JavaScript对象更加数字化

[英]Alter JavaScript Object to be more Numerical

我想改变这个JS对象。 我目前有:

for(var i = 0; i < destination_categories_selected.length; i++)
 {
  destination_categories_obj[i] = { 
                                   "category" : $(destination_categories_selected[i]).data("dkDropdownValue")
                                  }
 }

哪个输出和对象看起来像

[0] => "category" : 1,
[1] => "category" : 2,
[2] => "category" : 3

我可以这样做,以便类别完全删除到类似:

[0] => 1,
[1] => 2,
[2] => 3

如果我已正确理解您的问题,那么只需将值直接分配给相关的destination_categories_obj元素,而不是将对象分配给它:

for(var i = 0; i < destination_categories_selected.length; i++) {
    destination_categories_obj[i] = $(destination_categories_selected[i]).data("dkDropdownValue");
}
 for(var i = 0; i < destination_categories_selected.length; i++)
 {
  destination_categories_obj[i] = 
       $(destination_categories_selected[i]).data("dkDropdownValue");

 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM