Why I can't convert string to number without losing precision in JS?

I am guessing this is to solve the plusOne problem in leetcode. As others have answered, you cannot store value higher than the max safe integer. However you can write logic to add values manually. If you want to add one to the number represented in the array, you can use the below function. If you need to add a different value, you need to tweak the solution a bit.

var plusOne = function(digits) {
    let n = digits.length, carry=0;
    if(digits[n-1]<9){
        digits[n-1] +=1;        
    } else{
        digits[n-1] = 0;
        carry=1;
        for(let i=n-2;i>=0;i--){
            if(digits[i]<9){
                digits[i]+=1;
                carry=0;
                break;
            }else{
                digits[i]=0;
            }
        }
        if(carry>0){
            digits.unshift(carry);
        }
    }
    return digits;  
};