js 数据处理逻辑

<template>
	<div class="loading"></div>
</template>

<script>
	export default{
		mounted() {
			this.a()
			this.b()
			this.c()
			this.d()
			this.e()
			this.f()
			this.g()
			this.h()
			this.i()
			this.j()
			this.k()
			this.l()
		},
		methods:{
			// 转换为字符串
			a(){
				let a = 1
				let a1 = ["1", "2", "3"]
				let b = String(a);	console.log(b);console.log(typeof(b))
				let c = a.toString(); console.log(c);console.log(typeof(c))
				let d = String(a1); console.log(d);console.log(typeof(d))
				let e = a1.toString(); console.log(e);console.log(typeof(e))
			},
			// 转换为数组
			b(){
				let a = "1"
				let b = Number(a);	console.log(b);console.log(typeof(b))
			},
			// 合并数组
			c(){
				let a = [1, 2, 3]
				let b = [4, 5, 6]
				let c = a.concat(b); console.log(c)
				let d = new Set([1, 2, 3])
				let e = new Set([4, 5, 6])
				var f = new Set([...a, ...b]);console.log(f) //合并后变为对象了
			},
			// 数组中删除
			d(){
				let a = [1, 2, 3]
				let c = a.splice(1, 1); console.log(a);console.log(c);
			},
			// 字符串两端去掉空格
			e(){
				let a = "   你好   "
				let b = a.trim(); console.log(a);console.log(b);
			},
			// 数字取整
			f(){
				let a = "callpack1111"
				let b = a.split("callpack"); console.log(b);
				let c = 12.23321
				// 小数取整
				let d = parseInt(c); console.log(d);
				// 向下取整
				let e = Math.floor(c); console.log(e);
				// 向上取整
				let f = Math.ceil(c); console.log(f);
				// 四舍五入取整
				let g = Math.round(c); console.log(g);
				// 保留小数点
				let h = c.toFixed(2); console.log(h);
			},
			// 数组排序(还有冒泡排序, 快速排序, 插入排序)
			g(){
				let a = ["10", "3", "1", "5"]
				let b = [{i:10,b:"你好"},{i:3,b:"你也好"},{i:1,b:"你们好"},{i:5,b:"你们也好"}]
				let c = a.sort((a, b) => {a - b});  console.log(c);
				let d = b.sort((a, b) => a.i - b.i);  console.log(d);
			},
			// 数组排重(还有includes()、indexOf())
			h(){
				let a = ["10", "3", "1", "5", "1", "5"]
				let b = Array.from(new Set(a));	console.log(b)
				let c = [...new Set(a)]; console.log(c)
			},
			// 数组是否包含
			i(){
				let a = ["10", "3", "1", "5", "1", "5"]
				let b = "1"
				let c = "2"
				let d = a.includes(b); console.log(d);
				let e = a.includes(c); console.log(e);
			},
			// 过滤数组取大于等于5
			j(){
				let a = ["10", "3", "1", "5", "1", "5"]
				let b = a.filter((a)=> a >= 5 ); console.log(b);
			},
			//数组删除指定项
			k(){
				let a = ["10", "3", "1", "5", "1", "5"]
				let b = a.splice(0, 1);console.log(a);console.log(b);
			},
			// 字符串替换
			l(){
				let a = "callback(123456)"
				let b = a.replace("callback", "");console.log(b);
			}
		}
	}
</script>

<style lang="stylus" rel="stylesheet/stylus">

</style>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值