typescript数组篇章

typescript数组篇章,第1张

let nums=[];
//初始化元组
function nucity(addfromname:any){
    if (typeof addfromname===null||typeof addfromname==="undefined"){
        return;
    } else {
        nums.push(addfromname);
    }
}
//单条数据删除
function removes() {
    if(nums.length<=0) {
        console.log('删除失败!');
    } else {
        nums.splice(0,1);
        console.log(nums.length);
    }
}
//新增新的数据
function namethods(index:number,addnamety:any) {
//    首先传入要修改的下标
    if(index<0){
        console.log('错误下标');
    } else {
        nums.push(addnamety)
        console.log(nums)
    }
}
nucity('张三');
removes();
namethods(1,'李四')

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1297834.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-10
下一篇2022-06-10

发表评论

登录后才能评论

评论列表(0条)

    保存