1. 遍历方式实现
var turnNum = function(nums){
for(let i=0;i<nums.length;i++){
nums[i] = parseInt(nums[i])
}
return nums;
}
console.log(turnNum(['1','2','3'])) // [1,2,3]
2. Array map() 方法
var turnNum = function(nums){
return nums.map(Number);
}
console.log(turnNum(['1','2','3'])) // [1,2,3]
3. forEach()方法
var nums = ['1','2','3']
nums.forEach((item,index) =>{
nums[index] = parseInt(nums[index])
})
console.log(nums) // [1,2,3]