[英]Split a single array with respect to comma in javascript
我正在獲取單個字符串$scope.Obj= ["Talking Spanish,Spanish food,Spanish things,Football"];
的數組$scope.Obj= ["Talking Spanish,Spanish food,Spanish things,Football"];
拆分應該通過觀看,
我需要將其分解為["Talking Spanish","Spanish food","Spanish things","Football"];
我該如何使用JavaScript?
您可以使用拆分
let arr = ["Talking Spanish,Spanish food,Spanish things,Football"]; let op = arr[0].split(',') console.log(op)
您可以使用分割$ scope.Obj的第0個索引,然后將其重新分配給$ scope.Obj。
$scope={}; $scope.Obj= ["Talking Spanish,Spanish food,Spanish things,Football"]; $scope.Obj=$scope.Obj[0].split(",") console.log($scope.Obj);
str.split(separator,limit)上面是分割數組的常見語法https://medium.freecodecamp.org/how-to-make-your-react-native-app-respond-gracefully-when-the-keyboard -pops-up-7442c1535580
split()
方法通過使用指定的分隔符字符串確定將每個字符串拆分為多個子字符串,將字符串對象拆分為多個子字符串,從而將String對象拆分為字符串數組。
在下面的示例中, split()
在字符串中查找空格,並返回找到的前三個拆分。
var myString = 'Hello World. How are you doing?';
var splits = myString.split(' ', 3);
console.log(splits);
該腳本顯示以下內容:
["Hello", "World.", "How"]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.