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 remove the last character from an es6 string

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

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the es6 string how to remove the last character of the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, with a certain reference value, I believe that after reading this es6 string how to remove the last character of the article will have a harvest, let's take a look.

Methods: 1, use "[... str]" or "Array.from (str)" to convert the string into a character array; 2, delete the last element of the array with "arr.pop ()" or "arr.splice (- 1 str)"; 3, use "arr.join (") "to convert the processed array back to the string.

The operating environment of this tutorial: windows7 system, ECMAScript version 6, Dell G3 computer.

Es6 string removes the last character

In es6, to remove the last character of a string, you can use an array

1. Use the extension operator "." Or Array.from () converts a string to a character array

Var str = "abcdefg1234567" var arr1= [... str]; var arr2=Array.from (str); console.log (arr1); console.log (arr2)

2. Delete the last element of the character array

You can use the pop () function

Var str = "abcdefg1234567" var arr1= [... str]; console.log (arr1); console.log (arr1.pop ()); console.log (arr1)

You can also use the splice () function

Var str = "abcdefg1234567" var arr1= [... str]; console.log (arr1); arr1.splice (- 1Magne1); console.log (arr1)

3. Convert the processed array back to the string

Var s = arr1.join (""); / / specify the delimiter console.log (s); / / return the string

This is the end of the article on "how to remove the last character from an es6 string". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to remove the last character from the es6 string". If you want to learn more, you are welcome to follow the industry information channel.

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