从返回的json格式的data数据内随机取得n个
var arr=[ { "ceo":"张无忌", "conmpany":"阿里妈妈有限公司", "address":"上海市淮海路1888号508" }, { "ceo":"马云", "conmpany":"阿里巴巴有限公司", "address":"上海市陆家嘴浦东大道1800号" }, { "ceo":"雷军", "conmpany":"小小米亚", "address":"上海市淮海路568号508" }, { "ceo":"马画藤", "conmpany":"腾讯公司", "address":"上海市淮海路1200号512" }, { "ceo":"劉德華", "conmpany":"腾讯公司", "address":"上海市淮海路666号508" }, { "ceo":"周星驰", "conmpany":"华谊公司", "address":"上海市淮海路1256号508" }, { "ceo":"张学友", "conmpany":"畅想公司", "address":"上海市浦东大道666号508" }, { "ceo":"莫文蔚", "conmpany":"你好公司", "address":"上海市淮海路6856号508" }, { "ceo":"赵本山", "conmpany":"二人转公司", "address":"上海市徐汇区66886号508" } ]; function getRandom(n){ var newarr=[],id,leng=arr.length; for(var i=0;i<n;i++){ id=Math.floor(Math.random()*leng); newarr.push(arr[id]); } return newarr; } getRandom(3);
-----------------------------------------------------------------------小二给我来二两轮子!