超过一万转为带有两位小数点的万
formatNumber(num) {
num = Number(num);
if (num == 0) {
return num + '';
} else
if (num > 1 && num < 10000) {
return num + '';
} else {
return (num / 10000).toFixed(2) + '万';
}
}
forEach
let objDemo= [
{
"size":1,
"amt":3,
"cTime":"2021.10"
},
{
"size":2,
"amt":4,
"cTime":"2021.11"
},
{
"size":5,
"amt":3,
"cTime":"2021.12"
}
]
let arrTime3 = []
let arrSize3 = []
let arrAmt3 = []
this.objDemo.forEach(e=>{
arrTime3.push(e.cTime)
arrSize3.push(e.size)
arrAmt3.push(e.amt)
})
this.arrTime=arrTime3
this.arrSize=arrSize3
this.arrAmt3=arrAmt3
数组中筛选出最小值
arrAmt = [1,2,3,4,5,6,7]
let minNum= arrAmt.reduce((x,y)=> x<y ? x:y)
console.log(minNum)
arr.slice()
var arr1 = ['arr1', 'arr2', 'arr3', 'arr4', 'arr5', 'arr6'];
var newarr1 = arr1.slice(1, 5);
console.log(newarr1);
console.log(arr1);
var newarr2 = arr1.slice(1);
console.log(newarr2);
arr.map()
const array1 = [1, 4, 9, 16];
const map1 = array1.map((x) => x * 2);
console.log(map1);
var allData = [
{ name: '北京', value: 30 },
{ name: '伤害', value: 1946 },
{ name: '陕西', value: 5407 },
{ name: '西安', value: 8466 },
{ name: '广州', value: 5666 },
{ name: '深圳', value: 35 }
];
var provinceArr = this.allData.map((item) => {
return item.name;
});
var valueArr = this.allData.map((item) => {
return item.value;
});
console.log(provinceArr);
console.log(valueArr);
arr.forEach()
var arr = [1, 3, 5, 13, 2];
var res = arr.forEach(function (item, index) {
console.log(item, index);
});
console.log(res);
var newval = [
{ name: '输电', y: 28 },
{ name: '变电', y: 20 },
{ name: '配电', y: 10 },
{ name: '新业务', y: 3 }
];
var peiData = [];
newval.forEach((item) => {
peiData.push({
name: item.name,
y: item.y * 1,
h: item.y * 1.5
});
});
console.log(peiData);
[
{ name: '输电', y: 28, h: 42 },
{ name: '变电', y: 20, h: 30 },
{ name: '配电', y: 10, h: 15 },
{ name: '新业务', y: 3, h: 4.5 }
];
arr.every()
var arr = [1, 8, 19, 48, 10];
var flag = arr.every((item) => {
return item < 100;
});
console.log(flag);