我在 angular2 中创建了一个管道,我想在其中拆分空格上的字符串,然后将其作为数组读取。
let stringToSplit = "abc def ghi";
StringToSplit.split(" ");
console.log(stringToSplit[0]);
当我记录这个时,我总是得到“a”作为输出。我哪里错了?
最佳答案
做了一些改变:
let stringToSplit = "abc def ghi";
让 x = stringToSplit.split("");
console.log(x[0]);
split 方法返回一个数组。您不是使用其结果,而是获取原始字符串的第一个元素。
关于javascript - 根据空格拆分字符串并在angular2中读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44900110/