search
HomeWeb Front-endFront-end Q&AHow to remove the last character from es6 string

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

How to remove the last character from es6 string

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

Remove the last character from an es6 string

In es6, if you want to remove the last character from a string, you can use an array

1. First use the spread operator "..." or Array.from() to convert the string into a character array

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

How to remove the last character from es6 string

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);

How to remove the last character from es6 string

You can also use the splice() function

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

How to remove the last character from es6 string

3. Convert the processed array back to a string

var s =arr1.join("");  //指定分隔符
console.log(s);  //返回字符串

How to remove the last character from es6 string

##[Related Recommended:

javascript video tutorial, web front-end

The above is the detailed content of How to remove the last character from es6 string. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
es6怎么判断是否为数组es6怎么判断是否为数组Apr 25, 2022 pm 06:43 PM

在es6中,可以利用“Array.isArray()”方法判断对象是否为数组,若判断的对象是数组,返回的结果是true,若判断对象不是数组,返回的结果是false,语法为“Array.isArray(需要检测的js对象)”。

es6怎么去掉字符串所有空格es6怎么去掉字符串所有空格May 19, 2022 pm 03:32 PM

在es6中,可以通过replace()方法去掉字符串的所有空格,只需要使用replace()方法配合正则表达式“/\s/g”来查找字符串中的全部空格,并将其替换为空字符即可;去除语法为“字符串对象.replace(/\s/g,"")”。

es6中怎么判断两个对象是否相等es6中怎么判断两个对象是否相等Apr 19, 2022 pm 03:34 PM

在es6中,可用Object对象的is()方法来判断两个对象是否相等,该方法检测两个变量的值是否为同一个值,判断两个对象的引用地址是否一致,语法“Object.is(对象1,对象2)”;该方法会返回布尔值,若返回true则表示两个对象相等。

es6怎么将数字转为字符串es6怎么将数字转为字符串Apr 19, 2022 pm 06:38 PM

转换方法:1、利用“+”给数字拼接一个空字符,语法“数字+""”;2、使用String(),可把对象的值转换为字符串,语法“String(数字对象)”;3、用toString(),可返回数字的字符串表示,语法“数字.toString()”。

sort排序是es6中的吗sort排序是es6中的吗Apr 25, 2022 pm 03:30 PM

sort排序是es6中的;sort排序是es6中用于对数组的元素进行排序的方法,该方法默认不传参,按照字符编码顺序进行排序,排序顺序可以是字母或数字,并按升序或降序,语法为“array.sort(callback(a,b))”。

es6怎么改变数组数据es6怎么改变数组数据Apr 26, 2022 am 10:08 AM

改变方法:1、利用splice()方法修改,该方法可以直接修改原数组的内容,语法为“数组.splice(开始位置,修改个数,修改后的值)”;2、利用下标访问数组元素,并重新赋值来修改数组数据,语法为“数组[下标值]=修改后的值;”。

import as在es6中的用法是什么import as在es6中的用法是什么Apr 25, 2022 pm 05:19 PM

在es6中,import as用于将若干export导出的内容组合成一个对象返回;ES6的模块化分为导出与导入两个模块,该方法能够将所有的导出内容包裹到指定对象中,语法为“import * as 对象 from ...”。

ie8是否支持es6ie8是否支持es6Apr 19, 2022 pm 02:00 PM

ie8不支持es6。在ie浏览器中,ie10及以下版本是完全不支持es6的,解析不了es6的语法,而ie11可以支持部分es6特性;可以通过判断ie浏览器是否支持箭头函数来检查它是否支持es6,当不支持箭头函数,则代表浏览器不支持ES6。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.