1.字符串轉數組
split();
2.數組轉字符串
toString();join();toLocalstring();String()
3.去重
unique(str) {
let arr = str.split(',');
return Array.from(new Set(arr)).toString(); // 利用Array.from將Set結構轉換成數組
},
4.刪除多餘逗號
delateDouhao(str1, str2) {
let arr1 = str1.split(',');
let arr2 = [];
arr1.map((item) => {
if (item !== '' && item != undefined) {
arr2.push(item);
}
});
str2 = arr2.join(',');
return str2;
},
5.字符串返回符合條件的值
strToVal(str, val) {
let str1 = str.split(',');
let str2 = str1.filter((item) => item.includes(val));
return str2.join(',');
},
6. 對象賦key值
objFuzhi(arrA, arrB) {
Object.keys(arrA).forEach((key) => {
arrA[key] = arrB[key] || arrA[key];
});
},
7.對象賦值
A,B均爲對象,擴展運算符,
A= { …A, …B};
8.判斷undefined和null
let A = ''
let exp = undefined;
if ( A=== exp) {
//
return undefined
}
if ( A=== null) {
//
return null
}
9.遍歷對象
for (let variable in this.searchForm) {}
Object.keys(this.spanData1).map((key) => {})