边写边学js

文章讲述了在IT开发中如何通过遍历接口数据,检查和筛选特定属性(如shuxing1,shuxing2,和shuxing3),进行数组操作,以及处理金额、时间的比较和数据类型的转换,最后设置环境变量的过程。
摘要由CSDN通过智能技术生成

或筛选的遍历all筛选条件 for if request

//前置:之前的接口调用得到list包含id和相关shuxing1和shuxing2 
//判断某id是否是3中属性或关联的聚合数据
const shuxing1 = response["xxx"]["shuxing1"];
const shuxing2 = response["xxx"]["shuxing2"];
const id = response["1509"]["id"]
const un_shuxing1 = []; //非属性1的index
const un_shuxing2 = [];   //非属性2的index
const account = []    //需要判断是否属性3id
//比对数组每个值,不是1就输出位置,位置是非新能源的  un_shuxing1是位置数组
for(var i=0;i<shuxing1.length; i++){
   if(shuxing1[i] != 1){
       un_shuxing1.push(i)
   }
}
eo.info("不符合shuxing1的有:"+un_shuxing1)
// 如果有非shuxing1的,再排查un_shuxing1里的数据筛选un_shuxing2 
if(un_shuxing1.length!=0){
    for(var i=0;i<un_shuxing1.length;i++){
        if(shuxing2[un_shuxing1[i]]!="xxxxxx"){
            un_shuxing2.push(un_shuxing1[i])
        }
    }
}
eo.info("不符合shuxing2的有:"+un_shuxing2)
//如果排除以上两种条件还有未匹配的,需要去校验是否是shuxing3
if (un_shuxing2.length!=0){
    for(var i=0;i<un_shuxing2.length;i++){
        account.push(id[un_shuxing2[i]])
    }
    eo.error("xxxx")
    eo.info("xxxx")
}
//校验shuxing3
if (un_shuxing2.length!=0){
api = eo.env.param.get("api")
    //定义需要测试的API
    var request = {
        "url": xxxxx, 
        "name": "xxxx", 
        "method": "GET", 
        "headers": {
            "Content-Type": "application/x-www-form-urlencoded"
        }, 
        "timelimit": 1000 
    };
    var res = eo.execute(request);
    eo.info(res.response)
}

将数组改为合适的字符串 toString()

function jiequstr(a,b){
    const stra = a.toString().substr(0,b)
    return stra
}
//把上个接口返回的id搞成数组
const id = response["1509"]["id"]
//toString()变成字符串后求length
var len = id.toString().length
eo.info(len)
eo.info(id)
//用上面那个方法
const stra = jiequstr(id,len)
eo.info(stra)
//设置环境变量
eo.env.param.set("id_num",stra)

金额比较大小,改数据类型 Number()

//声明新变量时,使用关键词 "new" 来声明其类型  var carname=new String;var x= new Number;var y=new Boolean;
//var cars=new Array;var person=new Object;
amount_1 = response["1551"]["amount_1"][0]
amount_2 = response["1551"]["amount_2"][0]
//使用parseFloat(str)改变为浮点数
//var amount_1 = parseFloat(amount_1)
//var amount_2 = parseFloat(amount_2)
//直接用Number()
amount_1 = Number(amount_1)
amount_2 = Number(amount_2)
if(amount_1 >= amount_2){
    eo.info("排序正确")
}else if(amount_1 < amount_2){
    eo.info("排序错误")
}else{
    eo.info("aiaiai")
}
eo.info(amount_1+"     "+amount_2)
eo.info(typeof amount_1)

时间比较,改数据类型 Date.parse()

//获取流失时间后进行比较
var a = response["1286"]["000"][0]
var b = response["1286"]["111"][0]
if (a <= b){
    eo.info("流失时间升序排序正确"); //输出信息
    eo.info(a);
    eo.info(b);
}else{
    eo.error("流失时间升序排序错误"); //输出信息
    eo.info(a);
    eo.info(b);
}
var c = response["1289"]["000"][0]
var d = response["1289"]["111"][0]
if (c >= d){
    eo.info("流失时间降序排序正确"); //输出信息
    eo.info(c);
    eo.info(d);
}else{
    eo.error("流失时间降序排序错误"); //输出信息
    eo.info(c);
    eo.info(d);
}

var lose_maintain_last_time_1 = response["1553"]["lose_maintain_last_time_1"][0]
var lose_maintain_last_time_2 = response["1553"]["lose_maintain_last_time_2"][0]
var lose_maintain_last_time_1 = Date.parse(lose_maintain_last_time_1)
var lose_maintain_last_time_2 = Date.parse(lose_maintain_last_time_2)
if(lose_maintain_last_time_1>=lose_maintain_last_time_2){
    eo.info("最近维护时间排序正确")
}else{
    eo.error("最近维护时间排序错误")
}
eo.info(typeof lose_maintain_last_time_2)
eo.info(lose_maintain_last_time_2)   //1703116800000 转成整天的时间戳了
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值