Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use es6 to convert a string to an array

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how to use es6 to convert strings into arrays. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article. Es6's method of converting a string into an array: 1. Using the extension operator "...", syntax "[..." The string "]"; 2. Using the array extension method from (), the syntax "Array.from (" string ")".

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

The method of converting es6 string to Array

Method 1:

Use the array extension of ES6. The extension operator (spread) is three dots (...). It is like the inverse operation of rest parameters, converting an array into a sequence of parameters separated by commas.

[... "abcdefg1234567"]

Results:

Method 2:

In es6, you can use the array extension method Array.from () to convert strings into arrays, and the Array.from method is used to turn two types of objects into real arrays: array-like objects (array-like object) and iterable objects (including ES6's new data structures Set and Map).

Array.from ("hello")

Results:

On how to use es6 to convert strings into arrays to share here, I hope the above can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report