答案 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]
从字符串转换为数字。