1、计算滚动条长度,求最大值*1.2规定长度
const maxValue = Math.max(...data.map(item => item[2])) * 1.2;
考虑当数据都是0的时候,加判断
width: maxValue ? judgeDataShowWidth(maxValue, item[2]) : 0,
//计算长度的方法
function judgeDataShowWidth(maxValue: number, value: number): string {
console.log(`${Number(value / maxValue * 100).toFixed(0)}%`);
return `${Number(value / maxValue * 100).toFixed(0)}%`;
}
2、Object.assign() 多个对象合并到一个对象
a = {checkId: '2'} ;
b = { zdzmj: 98.8, zjzmj: 0 }
Object.assign(a, b) // { checkId: '2', zdzmj: 98.8, zjzmj: 0 }
3、concat数组合并
arr1=[{ checkId: '2', zdzmj: 98.8, zjzmj: 0 }];
arr2=[{ checkId: '2222', zdzmj: 98.822, zjzmj: 99 }];
arr1.concat(arr2)
//[
{ checkId: '2', zdzmj: 98.8, zjzmj: 0 },
{ checkId: '2222', zdzmj: 98.822, zjzmj: 99 }
]
4、uniq去除数组里重复的对象或者字符
arr1 = [
{ checkId: '2', zdzmj: 98.8, zjzmj: 0 },
{ checkId: '2', zdzmj: 98.8, zjzmj: 0 },
{ checkId: '2222', zdzmj: 98.822, zjzmj: 99 }
]
uniq(arr1)
//
[
{ checkId: '2', zdzmj: 98.8, zjzmj: 0 },
{ checkId: '2222', zdzmj: 98.822, zjzmj: 99 }
]
4、Object.keys()针对的是获取对象的属性,如果是数组,只能获取到下标的数组
5、difference,去除2个数组里一样的,保留不同的
const a = ["1", "2", "3"];
const b = ["2"]
difference(a, b); //["1", "3"];