• 从返回的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);
  • 相关阅读:
    第 5 章 Nova
    第 5 章 Nova
    第 5 章 Nova
    第 5 章 Nova
    第 5 章 Nova
    第 5 章 Nova
    第 5 章 Nova
    vba:提取字符串中间字符
    vba:根据给定单元格搜索目标值
    vba:合并当前目录下所有工作簿的全部工作表
  • 原文地址:https://www.cnblogs.com/-walker/p/6646944.html
Copyright © 2020-2023  润新知