将javascript对象转换为数组。如何? [英] Cast javascript object to array. How to?

查看:160
本文介绍了将javascript对象转换为数组。如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了这个沙盒测试:

<html>
    <head>
        <title>whatever</title>
        <script type="text/javascript">
            function myLittleTest() {
                var obj, arr, armap;

                arr = [1, 2, 3, 5, 7, 11];

                obj = {};
                obj = arr;
                alert (typeof arr);
                alert (typeof obj);

                // doesn't work in IE
                armap = obj.map(function (x) { return x * x; });
                alert (typeof armap);

            }
            myLittleTest();
        </script>
    </head>
    <body>
    </body>
</html>

我意识到我可以使用jQuery的函数$ .map来使这行代码工作,但是,什么我错过了javascript数据类型吗?

I realize I can use jQuery's function $.map for making that line of code work, but, what am I missing on javascript datatypes?

推荐答案

我很确定这不是类型问题,因为IE没有'在IE 9之前有 Array.map()函数。参见 http://msdn.microsoft.com/en-us/library/k4h76zbx(v = VS.85).aspx 获取列表支持的功能。请参阅 http://msdn.microsoft.com/ en-us / library / ff679976(v = VS.94).aspx ,了解IE 9中 Array.map()的功能。

I'm pretty sure this isn't a type problem, it's because IE didn't have the Array.map() function until IE 9. See http://msdn.microsoft.com/en-us/library/k4h76zbx(v=VS.85).aspx for a list of supported functions. See http://msdn.microsoft.com/en-us/library/ff679976(v=VS.94).aspx for a description of the Array.map() function in IE 9.

这篇关于将javascript对象转换为数组。如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆