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