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
Install crontab yum install crontabs CentOS 7 com...
Table of contents Implementing HTML Add CSS Imple...
Table of contents Preface first step: Step 2: Mod...
1. Grammar: <meta name="name" content...
Table of contents 1. Declare and initialize array...
1: Introduction to syslog.conf For different type...
Students who make websites often find that some n...
Before the release of Microsoft IE 5.0, the bigges...
Table of contents 1. Introduction 2. Main text 2....
I encountered such a problem during development A...
Problem 1: Baidu Map uses tiled images (the map i...
This article records the installation tutorial of...
This article describes the usage of MySQL stored ...
1. The error information reported when running th...
In our daily development work, text overflow, tru...