Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays Typescript:如何从数组中删除最后一项_Arrays_Angular_Typescript - Fatal编程技术网

Arrays Typescript:如何从数组中删除最后一项

Arrays Typescript:如何从数组中删除最后一项,arrays,angular,typescript,Arrays,Angular,Typescript,我有一个数组: ["one-", "two-", "three-", "testing-"] 转换成字符串后 "one-,two-,three-,testing-" 测试后如何移除最后一个charecter hypen(-),以及如何获得新阵列 接受输出 ["one-", "two-", "three-", "testing"] 请帮帮我。对于优雅的解决方案,请使用.slice(0,-1)作为字符串: let newString = "one-,two-,three-,testing-".

我有一个数组:

["one-", "two-", "three-", "testing-"]
转换成字符串后

"one-,two-,three-,testing-"
测试后如何移除最后一个charecter hypen(-),以及如何获得新阵列

接受输出

["one-", "two-", "three-", "testing"]

请帮帮我。

对于优雅的解决方案,请使用
.slice(0,-1)
作为字符串:

let newString = "one-,two-,three-,testing-".slice(0, -1); // "one-,two-,three-,testing"
要获取新数组,只需使用
.split(',')

这样做:

var str = "one-,two-,three-,testing-";
str = str.substring(0, str.length - 1);
从字符串中去掉最后一个字符。然后,要将其编入列表:

var newList = str.split(“,”);
试试这个

var newList = str.split(“,”);
const array = ["one-", "two-", "three-", "testing-"];
let DataStr = array.toString();
let OutputStr = DataStr.replace("-", "");
var res = OutputStr.split(",");
console.log(res);