TAG标签之数组操作

转换带逗号的对象成数组

			authType =1,2
			 this.authType = this.authType.split(",")
			 // [1,2]

转换string成数组、

		authType =1,2
        c= Object.values(this.authType);
        [1]

tostring


	c=1
	this.authType.toString
	// '1'
	

查找数组中是否包含X值 indexOf


	num:number=1;
	 
	authType.indexOf(this.num.toString()) > -1;
	// true
	

push 向数组中增加值


	tag=[1] 
	this.authType.push(2);
   // [1,2]
   

fliter 数组中删除指定的值

   this.authType =['1','2'];
   tag='2'; 		
   this.authType = this.authType.filter(t => t !== tag);
   // ['1']
   // 如果tag不存在就会报错 

// 完整的数组添加与删除 用于tag标签
  handleChange(checked: boolean, tag: string): void {
    if (checked) {
      this.authType.push(tag);
    } else {
      this.authType = this.authType.filter(t => t !== tag);
    }
   // console.log('我的授权: ', this.authType);
  }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值