繁体   English   中英

在javascript中针对逗号分割单个数组

[英]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); 

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM