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
1. The ENV instruction in the Dockerfile is used ...
background: Since the company's projects seem...
What is the nobody user in Unix/Linux systems? 1....
Sublime Text 2 is a lightweight, simple, efficien...
This tutorial uses CentOS 7 64-bit. Allocate 2GB ...
Table of contents How to rename MySQL database Th...
1. Design source code Copy code The code is as fol...
It's embarrassing to say that I had to search ...
In actual projects, the up and down scroll bars a...
Table of contents 1. HTTP Range Request 1.1 Range...
The new project has basically come to an end. It ...
Table of contents The CSS custom variable functio...
Table of contents Preface first step: Step 2: Mod...
Prerequisite: Percona 5.6 version, transaction is...
Table of contents 1. CDN introduction 1.1 react (...