1. Array Induction1. Split a string into an arrayconsole.log(Array.form("red")) // ["r", "e", "d"] 2. Convert collections and maps to new arraysconst a1 = new Map().set("name","张三").set("age",18) console.log(Array.from(a1)) // [["name","张三"], ["age",18] 3. Make a shallow copy of an existing arrayconst a1 = [ { name: "Xiao Ming", age: 18, gender: "male" }, { name: "Xiao Ming", age: 18, gender: "male" }] const a2 = Array.from(a1) console.log(a2) Running results: 4. The arguments object can be easily converted to an arrayfunction argumentArray() { console.log(Array.from(arguments)) // [1, 2, 3, 4] } argumentArray(1, 2, 3, 4) 5. Convert custom objectslet arrayLike = { 0: 'Zhang San', 1: '18', 2: 'Male', 3: ['Guess', 'Which one'], 'length': 4 } let arr = Array.from(arrayLike); console.log(arr); Running results: Array.of(1, 2, 3, 4) // [1, 2, 3, 4] 2. Iterator Method There are three methods on the Array.of(1, 2, 3, 4) // [1, 2, 3, 4] let user = [ { name: "Zhang San", age: 18, gender: "male" }, { name: "Li Si", age: 19, gender: "female" }, { name: "Wang Wu", age: 20, gender: "female" } ] First use console.log(Array.from(user.keys())) // [0, 1, 2]
console.log(Array.from(user.values()))
console.log(Array.from(user.entries())) 3. Common array operations
let newData = {"username": "ys","age": "22","gender":"Ji Ke 1902","className":"Class 3","id":6} person.splice(1,1,newData) // This is where the replacement is used This is the end of this article on the detailed summary of You may also be interested in:
|
<<: How to modify the MySQL character set
>>: Zabbix WEB monitoring implementation process diagram
MySQL version: MySQL Community Edition (GPL) ----...
Table of contents 1. Introduction 2. Direct recov...
Reflections on the two viewpoints of “people-orie...
Table of contents A chestnut to cover it Paramete...
The emergence of jQuery has greatly improved our ...
Prerequisite: You need to compile the ngx_http_he...
When the front-end requests the interface, it is ...
MySQL download and installation (version 8.0.20) ...
1. Pull the redis image docker pull redis 2. Star...
The attributes of the <TD> tag are used to ...
This article uses examples to illustrate the sear...
Preface Everyone knows how to run a jar package o...
1. Summary: In general, they can be divided into ...
This article example shares the specific code of ...
Table of contents 1. Class 1.1 constructor() 1.2 ...