1

I've this array of strings which all are numbers

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

Expected output:

b = [11, 15, 16, 17];
Mohammad Usman
  • 34,173
  • 19
  • 88
  • 85
Alexander
  • 19
  • 2

2 Answers2

4

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

var b = a.map(Number);

console.log(b);
bill.gates
  • 12,086
  • 2
  • 10
  • 33
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)
Manos Kounelakis
  • 2,419
  • 4
  • 25
  • 48