我想分开数组

时间:2017-09-20 04:30:43

标签: javascript angularjs split comma

enter image description here

我想打印一下:

name: 100 * 20, price: 100
name: 100 * 30, price: -2000
name: 100 * 40, price: 3000

1 个答案:

答案 0 :(得分:1)

如果要将价格转换为正值,可以尝试在循环中使用NSMutableDictionary<NSString *, NSArray<NSString *>> *alphabetDict = [[NSMutableDictionary alloc] init]; // Then you can add each array to the dictionary. // For example: NSString *keyA = @"A"; NSArray<NSString *> *arrayForA = @[ @"Aardvark", @"Apple" ]; [alphabetDict setValue:arrayForA forKey:keyA]; // Repeat to add each array to the dict. 方法。然后在循环中将abs()的元素推入arrString

items

$scope.items = []; for (i = 0; i < $scope.arrString.length; i++) { console.log("size: " + $scope.arrString[i] + " price: " + $scope.arrString1[i]); $scope.items.push({ name: $scope.arrString[i], price: Math.abs(+$scope.arrString1[i]) }); } for (i = 0; i < $scope.items.length; i++) { console.log("size: " + $scope.items[i].name + ", price: " + $scope.items[i].price); } 语句正在将+$scope.arrString1[i]从字符串转换为数字。