1

I've this array of strings which all are numbers

var a = ['11', '15', '16', '17'];

Expected output:

b = [11, 15, 16, 17];
2
  • 7
    b = a.map(Number) Commented May 7, 2020 at 10:34
  • a = ['11', '15', '16', '17'].map(item =>parseInt(item,10) Commented May 7, 2020 at 10:34

2 Answers 2

4

var a = ['11', '15', '16', '17'];

var b = a.map(Number);

console.log(b);

Sign up to request clarification or add additional context in comments.

Comments

0

You can use a loop, and convert each element of the array containing string, into a integer. parseInt() is a method which converts string into a integer, it takes two arguments, first: the string, second: the base number of the integer

var a=["1","2","3"]; 
console.log(a); 
b=[]; 
for(i=0;i<3;i++){
    b[i]=parseInt(a[i],10)
}; 
console.log(b)

1 Comment

It's SImpler and more Logical

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.