当前位置:网站首页>ES6 cycle filter value
ES6 cycle filter value
2022-07-24 18:09:00 【Jiojio is learning le】
About es6 Some applications and Other processing of front and rear data
List of articles
- About es6 Some applications and Other processing of front and rear data
- One 、 Add an attribute to the object in the array
- Two 、 Drop down to get id Get other properties
- 3、 ... and 、 Property substitution
- Four 、 Traverse the array as 【1,2,3,4】
- 5、 ... and 、 Filter the array according to conditions
- 6、 ... and 、 Tree structure settings disabled attribute
- 7、 ... and 、 Traversal array Modify attribute values
- 8、 ... and 、 Traversal array Add property value
- Nine 、 Array A There are arrays B Data will be deleted
- Ten 、es6 Two arrays take the same item and different items
- 11、 ... and 、 from json And return a new array or string
- Twelve 、 Delete an attribute in an object or array
- fourteen 、 toggle case
- 15、 ... and 、 Object array de duplication
- sixteen 、 The order of a field in the array
- seventeen 、 Add new attributes to the array in the array
- eighteen 、 analysis headers in content-disposition File name
- nineteen 、 Find the subscript of the selected value
- twenty 、es6 Compare two arrays if a field is the same , Assign a value to a field
One 、 Add an attribute to the object in the array
this.data.forEach((item,index)=>{
needData.push(
Object.assign({
},item,
{
'addAttr':'addAttrContent'})
)
})
Two 、 Drop down to get id Get other properties
let currentItemSkuUnit = {
};
currentItemSkuUnit = this.specKeyData.find((item) => {
return item.id === value;
});
this.detailForm.specRatio = currentItemSkuUnit.specRatio;
3、 ... and 、 Property substitution
this.addFormDataOne = JSON.parse(JSON.stringify(this.addFormDataOne).replace(/cusAddress/g, 'address'))
Four 、 Traverse the array as 【1,2,3,4】
this.detailForm.areas = [];
this.categoryData.map((item) => {
this.detailForm.areas.push(item.whAId);
});
5、 ... and 、 Filter the array according to conditions
this.detailForm.owners = this.detailForm.owners.filter((item) => {
return item !== "null";
});
6、 ... and 、 Tree structure settings disabled attribute
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)
7、 ... and 、 Traversal array Modify attribute values
data.forEach((item) => {
if (item.whState == 0) {
item.whState = false;
} else {
item.whState = true;
}
return data;
});
this.popupTreeData = data;
8、 ... and 、 Traversal array Add property value
var arr = [];
this.adjustType.forEach((item, index) => {
if (item.id !== row.state) {
arr.push(Object.assign({
}, item, {
disabled: true }));
this.adjustType = arr;
}
});
Nine 、 Array A There are arrays B Data will be deleted
arrayWeightRemoval(array1, array2) {
// Temporary array storage
var tempArray1 = []; // Temporary array 1
var tempArray2 = []; // Temporary array 2
for (var i = 0; i < array2.length; i++) {
tempArray1[array2[i]] = true; // Number of generals array2 The element value in is used as tempArray1 The key , The value is true;
}
for (var i = 0; i < array1.length; i++) {
if (!tempArray1[array1[i]]) {
tempArray2.push(array1[i]); // Filter array1 China and array2 Same element ;
}
}
return tempArray2;
}
Ten 、es6 Two arrays take the same item and different items
// identical
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"}
// identical
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 )
// Different
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 )
11、 ... and 、 from json And return a new array or string
data:[
{
'Id': '1',
'Phone': '123456',
'Name': ' Zhang San ',
},
{
'Id': '2',
'Phone': '78945',
'Name': ' Li Si ',
},
{
'Id': '3',
'Phone': '123789',
'Name': ' Wang Wu ',
}
]
//data json The name of ,n It is customized
let result = data.map(n=> n.name).join();//' Zhang San , Li Si , Wang Wu '
let results = data.map(n => n.name);//[' Zhang San ',' Li Si ',' Wang Wu ']
Twelve 、 Delete an attribute in an object or array
1. Delete an attribute in an object
let {
createTime, ...params } = data;
console.log(params)
This last params Is the value we need
2. Delete an attribute in the array
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;
}
``` # 13、 ... and 、 In the number of filter groups null An empty string 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)
>// Empty string cannot contain spaces
var arr = ['1','2','', '3.jpg','']
var newArr = arr.filter(item => item)
console.log(newArr)
fourteen 、 toggle case
// Capital conversion
function upperJSONKey(jsonObj){
for (var key in jsonObj){
jsonObj["\""+key.toUpperCase()+"\""] = jsonObj[key];
delete(jsonObj[key]);
}
return jsonObj;
}
// Lowercase conversion
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);
15、 ... and 、 Object array de duplication
const arr = [
{
name: ' Zhang San ',
age: 22
},
{
name: ' Li Si ',
age: 22
},
{
name: ' Zhang San ',
age: 23
}
]
const map = new Map()
const qc = arr.filter(key => !map.has(key.name) && map.set(key.name, 1)) // Here to name Attribute for de duplication
console.log('qc')
console.log(qc)
sixteen 、 The order of a field in the array
var detailsData = res.data.data.details;
detailsData.sort((old, New) => {
return old.diffNum - New.diffNum;
});
seventeen 、 Add new attributes to the array in the array
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);
eighteen 、 analysis headers in content-disposition File name
let filename = decodeURIComponent(
res.headers["content-disposition"].split("filename=")[1]
);
link.setAttribute("download", filename);
nineteen 、 Find the subscript of the selected value
changeZcodeEnd(value) {
const ZcodeData = ['a','b','c'];
const One = ZcodeData.findIndex((item) => {
return item == value;
});
console.log(One)
}
twenty 、es6 Compare two arrays if a field is the same , Assign a value to a field
this.tableHeadsSon.filter((item) => {
tableHeadsData.find((key) => {
if (item.prop == key.prop) {
return (item.width = key.width);
}
});
});
边栏推荐
- 《STL源码剖析》应该怎样读?
- 213. Looting II - Dynamic Planning
- pinia 入门及使用
- Introduction and use of Pinia
- SV casts and constants
- Learn redisson from scratch ------- topics (subscription and distribution)
- 0627~放假知识总结
- 文件上传漏洞——.user.ini与.htaccess
- Just one dependency to give swagger a new skin, which is simple and cool!
- Common methods of number and math classes
猜你喜欢

分家后印象笔记过日子依然不好过,骚操作却不少

Quickly complete the unit test junit4 setting of intelij idea

What are the pitfalls from single architecture to distributed architecture?

0625~<config>-<bus>

手写博客平台~第二天

T245982 「KDOI-01」醉花阴

Icml2022 Best Paper Award: learning protein reverse folding from millions of predicted structures

Interview assault 66: what is the difference between request forwarding and request redirection?

Shanghai Jiaotong University team used joint deep learning to optimize metabonomics research

Pay close attention! List of the latest agenda of 2022 open atom open source Summit
随机推荐
How to prepare for hyperinflation
Goodbye Navicat! This open source database management tool has a cooler interface!
redis集群的三种方式
深入解析著名的阿里云Log4j 漏洞
Polymorphism, abstract class, interface
Icml2022 Best Paper Award: learning protein reverse folding from millions of predicted structures
Use prometheus+grafana to monitor MySQL performance indicators
C language custom types - Enumeration
sklearn 的模型保存与加载使用
Still building projects from scratch? This upgraded rapid development scaffold is worth a try!
船新 IDEA 2022.2 正式发布,新特性真香!
pinia 入门及使用
【obs】依赖库: x264 vs 构建
Get the original data API on 1688app
05mysql lock analysis
阿里巴巴1688按关键字搜索商品 API 使用展示
颜色的13 个必备方法!
Bib | mol2context vec: context aware deep network model learning molecular representation for drug discovery
C language programming training topics: K characters in left-handed string, little Lele and Euclidean, printing arrow pattern, civil servant interview, poplar matrix
猜JWT关键字