1.filter(找指定元素)
数组中对象name值为空的:
var data= this.bbs.taxonomyList.filter(function(item){
return item.name == "";
})
2.过滤数组重复元素:
1.通常方法:
2.set
const myArr = [1,1,3,5,7,6,5,2]
const set = new Set(myArr)
console.log([...set])
set 有 size 属性。
set 可以通过 Array.from() 方法转换成数组,或者[...set]
3.对象-数组
let myObj = {0: 'a', 1: 'b', 2: 'c'};
let newObj = {...myObj, ...{length: 3}}
let arr = Array.from(newObj)
let arr1 = Object.values(myObj)
let arr2 = Object.keys(myObj)
let arr3 = Object.entries(myObj)
console.log(arr); // ["a", "b", "c"]
console.log(arr1);// ["a", "b", "c"]
console.log(arr2);// ["0", "1", "2"]
console.log(arr3);// [["0", "a"], ["1", "b"], ["2", "c"]]
传统for in方法;
let arr = [];
for (let i in myObj) {
arr.push(myObj[i]); //属性
//arr.push(object[i]); //值
}
对象中的键,值,键值获取;
var obj = { foo: 'bar', baz: 42 }; console.log(Object.keys(obj)) //["foo", "baz"] console.log(Object.values(obj)) //["bar", 42] console.logObject.entries(obj)) //[['foo', 'bar'], ['baz', 42]]