this.data.forEach((item,index)=>{
needData.push(
Object.assign({},item,
{'addAttr':'addAttrContent'})
)
})
let currentItemSkuUnit = {};
currentItemSkuUnit = this.specKeyData.find((item) => {
return item.id === value;
});
this.detailForm.specRatio = currentItemSkuUnit.specRatio;
this.addFormDataOne = JSON.parse(JSON.stringify(this.addFormDataOne).replace(/cusAddress/g, 'address'))
this.detailForm.areas = [];
this.categoryData.map((item) => {
this.detailForm.areas.push(item.whAId);
});
this.detailForm.owners = this.detailForm.owners.filter((item) => {
return item !== "null";
});
tickMenuIdFilter(arr, data) {
var newArr = [];
if (arr != undefined && arr.length > 0) {
newArr = arr.map((item) => {
item.disabled = data;
if (item.areaList != undefined && item.areaList.length > 0) {
this.tickMenuIdFilter(item.areaList, data);
}
return item;
});
}
console.log(newArr);
return newArr;
},
this.tickMenuIdFilter(this.popupTreeData, true)
data.forEach((item) => {
if (item.whState == 0) {
item.whState = false;
} else {
item.whState = true;
}
return data;
});
this.popupTreeData = data;
var arr = [];
this.adjustType.forEach((item, index) => {
if (item.id !== row.state) {
arr.push(Object.assign({}, item, { disabled: true }));
this.adjustType = arr;
}
});
arrayWeightRemoval(array1, array2) {
//临时数组存放
var tempArray1 = []; //临时数组1
var tempArray2 = []; //临时数组2
for (var i = 0; i < array2.length; i++) {
tempArray1[array2[i]] = true; //将数array2 中的元素值作为tempArray1 中的键,值为true;
}
for (var i = 0; i < array1.length; i++) {
if (!tempArray1[array1[i]]) {
tempArray2.push(array1[i]); //过滤array1 中与array2 相同的元素;
}
}
return tempArray2;
}
//相同
let arr = [{ id: 1, name: 'zs' }, { id: 2, name: 'ls' }, { id: 3, name: 'ww' }, { id: 4, name: 'xm' }, { id: 5, name: 'xh' },]
let sum = [3, 4, 5]
let date = arr.filter(item => sum.indexOf(item.id) > -1)
console.log('date', date)
// 0: {id: 3, name: "ww"}
// 1: {id: 4, name: "xm"}
// 2: {id: 5, name: "xh"}
//相同
let arr = [{ id: 1, name: 'zs' }, { id: 2, name: 'ls' }, { id: 3, name: 'ww' }, { id: 4, name: 'xm' }, { id: 5, name: 'xh' },]
let arr2 = [{ id: 1, name: 'zs' }]
let newArr = arr.filter((item) =>
arr2.some((ele) => ele.id === item.id)
);
console.log('newArr', newArr )
//不同
let arr = [{ id: 1, name: 'zs' }, { id: 2, name: 'ls' }, { id: 3, name: 'ww' }, { id: 4, name: 'xm' }, { id: 5, name: 'xh' },]
let arr2 = [{ id: 1, name: 'zs' }]
let newArr = arr.filter((item) =>
!arr2.some((ele) => ele.id === item.id)
);
console.log('newArr', newArr )
data:[
{
'Id': '1',
'Phone': '123456',
'Name': '张三',
},
{
'Id': '2',
'Phone': '78945',
'Name': '李四',
},
{
'Id': '3',
'Phone': '123789',
'Name': '王五',
}
]
//data json的名称,n是自定义取的
let result = data.map(n=> n.name).join();//'张三,李四,王五'
let results = data.map(n => n.name);//['张三','李四','王五']
1.删除对象中的某个属性
let { createTime, ...params } = data;
console.log(params)
最后这个params就是我们需要的值
2.删除数组中的某个属性
var arrayData = [
{
index: 0,
is_required: true,
name: "vmvdnksl",
type: "LONG_TEXT",
},
{
index: 1,
is_required: true,
name: "dsvnlk",
type: "MULTIPLE_SELECTORS",
},
];
for (let key in arrayData) {
delete arrayData[key].index;
}
```
# 十三、过滤组数中null 空字符串 undefined
```javascript
var arr = ['1','2',undefined, '3.jpg',undefined]
var newArr = arr.filter(item => item)
console.log(newArr)
var arr = ['1','2',null, '3.jpg',null]
var newArr = arr.filter(item => item)
console.log(newArr)
>//空字符串里面不能包含空格
var arr = ['1','2','', '3.jpg','']
var newArr = arr.filter(item => item)
console.log(newArr)
// 大写转换
function upperJSONKey(jsonObj){
for (var key in jsonObj){
jsonObj["\""+key.toUpperCase()+"\""] = jsonObj[key];
delete(jsonObj[key]);
}
return jsonObj;
}
// 小写转换
function lowerJSONKey(jsonObj){
for (var key in jsonObj){
jsonObj["\""+key.toLowerCase()+"\""] = jsonObj[key];
delete(jsonObj[key]);
}
return jsonObj;
}
var obj = {KEY:'value'};
var newObj = lowerJSONKey(obj);
console.log(newObj);
const arr = [
{
name: '张三',
age: 22
},
{
name: '李四',
age: 22
},
{
name: '张三',
age: 23
}
]
const map = new Map()
const qc = arr.filter(key => !map.has(key.name) && map.set(key.name, 1)) // 这里对name属性进行去重
console.log('qc')
console.log(qc)
var detailsData = res.data.data.details;
detailsData.sort((old, New) => {
return old.diffNum - New.diffNum;
});
this.detailList = res.data.data;
this.detailList.forEach((item, index) => {
if (item.allocateResult) {
var ResultData = [];
item.allocateResult.forEach((key) => {
ResultData.push(
Object.assign(key, {
inventoryOutStateTwo: item.inventoryOutState,
})
);
});
item.allocateResult = ResultData;
console.log(item.allocateResult);
let filename = decodeURIComponent(
res.headers["content-disposition"].split("filename=")[1]
);
link.setAttribute("download", filename);
changeZcodeEnd(value) {
const ZcodeData = ['a','b','c'];
const One = ZcodeData.findIndex((item) => {
return item == value;
});
console.log(One)
}
this.tableHeadsSon.filter((item) => {
tableHeadsData.find((key) => {
if (item.prop == key.prop) {
return (item.width = key.width);
}
});
});
var arr = [1, 2, 3, 4, 5];
arr.map(String); // ['1', '2', '3', '4', '5']
var arr2 = ['1', '2', '3', '4', '5']
arr2.map(Number); //[1, 2, 3, 4, 5]
new Intl.NumberFormat().format(350000)
//转换单位万
export function formatNumber(num) {
num = Number(num);
if (num == 0) {
return num + '';
} else if (num > 0 && num < 10000) {
return parseFloat((num).toFixed(2)) + '';
} else {
return (num / 10000).toFixed(2) + '万';
}
}
Promise.all([
new Promise((resolve, reject) => {
//请求A接口,这里用setTimeout模拟请求
setTimeout(() => {
resolve("A的结果");
}, 2000);
}),
new Promise((resolve, reject) => {
//请求B接口,这里用setTimeout模拟请求
setTimeout(() => {
resolve("B的结果");
}, 1000);
}),
])
.then((res) => {
console.log(res[0]); //A的结果
console.log(res[1]); //B的结果
//根据A和B的结果请求C接口数据
setTimeout(() => {
console.log("C的请求结果");
}, 100);
})
.catch((err) => {
console.log(err);
});
const arr = [
{
name: '张三',
age: 22
},
{
name: '李四',
age: 22
},
{
name: '张三',
age: 23
}
]
let results = arr .map(n => n.name);
let narr1 = [...new Set(results)]
const arr = [{date: "2018-11-18", name: "demo1"}, {date: "2018-11-19", name: "demo2"}];
const target = {};
arr.forEach(a => {
const source = JSON.parse(`{"${a.date}":"${a.name}"}`);//利用JSON.parse将对象
//格式直接造出来
Object.assign(target,source);
})
// console.log(target)
// target = {
//"2018-11-18":"demo1",
//"2018-11-19":"demo2"
}