码迷,mamicode.com
首页 > 编程语言 > 详细

JS获取数组小技巧

时间:2015-07-14 13:04:30      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

有如下数组

var infoArray = strTest.split(";");
            var points2;
            for (var i = 0; i < infoArray.length; i++) {
                var info = infoArray[i];
                points2 = info + "," + points2;
            }
            points2 = points2.substring(0, points2.length - 10);
            var points3 = "[" + points2 + "]";

生成的数组JS获取报错,修改如下正常

var infoArray = strTest.split(";");
            var str = "", points;
            for (var i = 0; i < infoArray.length; i++) {
                str += "," + infoArray[i];
            }
            points = eval("[" + str.substr(1) + "]");

JS获取数组小技巧

标签:

原文地址:http://www.cnblogs.com/pp521/p/4644984.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!