1. 字符串以逗号分隔成数组的方法 :
var list = code.split(',')
2. ["C230719000015", "C230719000015", "C230719000016"] 过滤掉相同的 :
使用Set数据结构来排除数组中的相同元素。Set是一种无重复值的数据结构,可以很方便地用来去除数组中的重复元素 。
var arr = ["C230719000015", "C230719000015", "C230719000016"];
var newArr = [...new Set(arr)];
console.log(newArr); // ["C230719000015", "C230719000016"]
3. var list = [1,2] list.push(1) 与list 值相同的 就不push 进去 不相同的push进去:
var list = [1, 2];
var element = 1;
if (!list.includes(element)) {
list.push(element);
}
console.log(list); // [1, 2]
4. map 方法返回一个新数组
var list = [
{extendNo: "C230719000015", ordOrderId: 424992053},
{extendNo: "C230719000015", ordOrderId: 424992053},
{extendNo: "C230719000016", ordOrderId: 424992053}
];
var extendNoArr = list.map(obj => obj.extendNo);
console.log(extendNoArr); // ["C230719000015", "C230719000015", "C230719000016"]
5. var arr = [{id: 1, name: "A"}, {id: 2, name: "B"}, {id: 1, name: "A"}, {id: 3, name: "C"}]
排除name为c 的返回新的数组
使用filter()方法来筛选出name不为"C"的元素,从而返回一个新的数组
var arr = [{id: 1, name: "A"}, {id: 2, name: "B"}, {id: 1, name: "A"}, {id: 3, name: "C"}];
var newArr = arr.filter(function(element) {
return element.name !== "C";
});
console.log(newArr); // [{id: 1, name: "A"}, {id: 2, name: "B"}, {id: 1, name: "A"}]
6. var downLoadList=[""] js将数组中 为""的去掉
var downLoadList = [""];
var filteredList = downLoadList.filter(function(element) {
return element !== "";
});
console.log(filteredList); // []
7. var fillingTechnology = "[\"填充工艺2.0\",\"填充工艺4.0\"]" js 转成 ["填充工艺2.0","填充工艺4.0"]
var fillingTechnology = "[\"填充工艺2.0\",\"填充工艺4.0\"]";
var fillingTechnologyArray = JSON.parse(fillingTechnology);
console.log(fillingTechnologyArray); // ["填充工艺2.0","填充工艺4.0"]
8. var fillingTechnology = ["填充工艺4.0","无"]
var a = '填充工艺4.0' , 判断fillingTechnology 是否包含 a
var fillingTechnology = ["填充工艺4.0", "无"];
var a = '填充工艺4.0';
var isContainsA = fillingTechnology.includes(a);
console.log(isContainsA); // true