Recently I saw some public accounts and found some useful ways to improve efficiency, although they are old methods, as a record

1. Quick weight removal

let num= ["one", "two","three", "four", "one"]; let newNum= Array.from(new Set(num)); //["one", "two","three", "four"];Copy the code

2. Find one of the numbers you want

let num = [{name:"one",value:"1"},{name:"two",value:"2"},{name:"three",value:"3"}]

let newNum = num.find(item =>{return item.name == "one"})//{name:"one",value:"1"}
Copy the code

3. Delete one of the specified data items

let num = [{name:"one",value:"1"},{name:"two",value:"2"},{name:"three",value:"3"}] num.splice(num.findIndex(item => Item. The name = = = "one"), 1) / / [{name: "two", the value: "2"}, {name: "three", the value: "3"}] / / by the way rapidly emptying array can use num. Length = 0; / / []Copy the code

4. Remove some null false values

let array= [0, "one",NaN, 1, true, undefined, false, ""];

let trueArray = array.filter(Boolean);

// returns ["one", 1, true]
Copy the code

5. Sum

Let nums = [1,2, 3, 4]; let sum = nums.reduce((x, y) => x + y); / / 10Copy the code

6. Merge arrays

Let num1 = [1,2, 3]; let num1 = [1,2, 3]; let num2 = ["one","two", "three"]; let num3 = ["a","b", "c"]; var concatNum = [...num1,...num2,...num3]; / / [1, 2, 3, "one", "two", "three", "a", "b", "c");Copy the code