如何将JS的对象类型转换成数组类型

如何将JS的对象类型转换成数组类型


慕田峪7331174
浏览 2025回答 4
4回答

森栏

只需要一句,arr.__proto__=[];但是要注意浏览器支持__proto__才行,最新的浏览器应该都支持。以下两种都可以解决此问题:function&nbsp;transform(obj){var&nbsp;arr&nbsp;=&nbsp;[];for(var&nbsp;item&nbsp;in&nbsp;obj){arr.push(obj[item]);}return&nbsp;arr;}或者public static void main(String[] args) {String [] s={"2","3","4"};int [] array=new int[3];for(int i=0;i<s.length;i++){array[i]=Integer.parseInt(s[i]);System.out.println(array[i]);}}

慕田峪4524236

1234567function&nbsp;transform(obj){&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;arr&nbsp;=&nbsp;[];&nbsp;&nbsp;&nbsp;&nbsp;for(var&nbsp;item&nbsp;in&nbsp;obj){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;arr.push(obj[item]);&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;arr;}&nbsp;&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP