i have value in input this:
7*7*0*0*32*17
i simple .split('*') obtain following arrays:
["7","7","0","0","32","17"]
then transform arrays numbers .map(number), arrays composed not of strings numbers:
[7,7,0,0,32,17]
what interests me second 7. use .slice(1,2) in order select alone. until point, works:
[7]
my problem is, can't add +1 transform 7 8. instead, returns 71.
let's call array of ["7","7","0","0","32","17"] -> "myarray" simplify whole stuff.
console.log(myarray); var myarraymapped = myarray.map(number); console.log(myarraymapped); var myarraysliced = myarraymapped.slice(1,2); console.log(myarraysliced); var myarrayincreased = myarraysliced + 1; console.log(myarrayincreased);
and here results of console.logs:
["7","7","0","0","32","17"] [7,7,0,0,32,17] [7] 71
everything works expected until line, doesn't work:
var myarrayincreased = myarraysliced + 1;
note final goal put 8 inside input, , reconstruct array 1 single string below, maybe there's simplier , faster solution haven't seen. basically, button call function add +1 specific part of value want select (the second "7"):
from:
7*7*0*0*32*17
to:
7*8*0*0*32*17
thanks in advance. note not want sum arrays, nor push new array among ones got (which topics i've seen through research, don't me). want maths 1 specific array.
instead of using slice
, select it's array index
myarraymapped[1] += 1;
which make final code
var myarray = ["7","7","0","0","32","17"]; console.log(myarray); var myarraymapped = myarray.map(number); console.log(myarraymapped); myarraymapped[1] += 1; console.log(myarraymapped);
Comments
Post a Comment