当前位置:网站首页>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);
}
});
});
边栏推荐
- int8 & int8,你栽过这样的跟头吗?
- Definition and storage of adjacency table and adjacency storage of directed graph and undirected graph
- Pay close attention! List of the latest agenda of 2022 open atom open source Summit
- 字符串常用方法(2)
- Laravel notes - RSA encryption of user login password (improve system security)
- redis集群的三种方式
- Shardingsphere database read / write separation
- JS数组方法 sort() 排序规则解析
- Go language file operation
- 0623~ holiday self study
猜你喜欢

Common methods of number and math classes

Bib | mol2context vec: context aware deep network model learning molecular representation for drug discovery

分家后印象笔记过日子依然不好过,骚操作却不少
去不图床容量兑换

Laravel笔记-用户登录时密码进行RSA加密(提高系统安全性)

T245982 「KDOI-01」醉花阴

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

C language to achieve a static version of the address book

C language custom type explanation - structure

Stream, file, IO
随机推荐
Alibaba /166 obtains the API instructions for all products in the store
还在从零开始搭建项目?这款升级版快速开发脚手架值得一试!
Blackmagic Fusion Studio 18
The use and Simulation of character and string library functions in C language
排序的几种方式for while 还有sort
0615~用自定义注解实现RBAC权限管理
sklearn 的模型保存与加载使用
T245982 「KDOI-01」醉花阴
Learn redisson from scratch ------- topics (subscription and distribution)
T245982 "kdoi-01" drunken flower Yin
1688/ Alibaba searches new product data by keyword API instructions
SV casts and constants
Goodbye Navicat! This open source database management tool has a cooler interface!
简单测试JS代码
Flink operation Hudi data table
如何遵循“低耦合”设计原则?
Shengxin commonly used analysis graphics drawing 02 -- unlock the essence of volcano map!
船新 IDEA 2022.2 正式发布,新特性真香!
C language programming training topics: K characters in left-handed string, little Lele and Euclidean, printing arrow pattern, civil servant interview, poplar matrix
Section 11 cache avalanche, hot data failure follow Daewoo redis ------- directory post