数组将字符串转换为数组angularjs

时间:2018-02-26 07:15:19

标签: javascript angular

$scope.stringArray = new Array();
  angular.forEach($scope.questions, function(value, key){
      if(value.type == 'select') {
          var string = value.value;
          console.log(string) //"This is item";
          for(var i =0; i < string.length; i++){
              $scope.stringArray.push(string[i]);
              if(i != string.length-1){
                  $scope.stringArray.push(" ");
              }
          }

      }
  });

它应该返回

stringArray [0] = "This"; stringArray [1] = "is"; stringArray [2] = "item";

目前的回应就是那样

stringArray [0] = "T"; stringArray [1] = ""; stringArray [4] = "h"; stringArray [5] = ""; stringArray [6] = "i";...  Please guide

0 个答案:

没有答案