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
  • 37,952
  • 20
  • 92
  • 95
Alexander
  • 19
  • 2

2 Answers2

4

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

var b = a.map(Number);

console.log(b);
bill.gates
  • 14,145
  • 3
  • 19
  • 47
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,848
  • 5
  • 31
  • 55