javascript - Unexpected token at JSON position -


when using json.parse achieve output expected getting error unexpected token b in json @ position 1. missing?

var string1 = "bodebo,carne";  var array1 = string1.split(',');  var string2 = "1,2";  var array2 = string2.split(',');      var =[]; var b = [];  for(var i=0;i<array1.length;i++){      var c = array1[i];      var d = array2[i];      e = "[" +  c +","+d +"]";      e =json.parse(e);      a.push(e);  }    console.log(a);

ouptput expected

[[ 'bodebo', '1'],[ 'carne','2' ]]; 

without json.parse

output

 [ '[bodebo,1]', '[carne,2]' ] 

i dont want ' ' on each array element

might make array if output expected has arrays.

var string1 = "bodebo,carne";  var array1 = string1.split(',');  var string2 = "1,2";  var array2 = string2.split(',');    var = [];  for(var = 0; < array1.length; i++){      a.push([array1[i], array2[i]]);  }    console.log(a);

but needs loops when have map?

var string1 = "bodebo,carne";  var array1 = string1.split(',');  var string2 = "1,2";  var array2 = string2.split(',');    console.log(array1.map((s, idx) => [s,array2[idx]]));


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -