-6

Convert

var a = [['12ae11ee12-1bhb222','2019-10-10T19:46.19.632z','a123']] 

to

var a= ['12ae11ee12-1bhb222','2019-10-10T19:46.19.632z','a123']

I dont want two square brackets in front and end.

I want output

a[2] = 'a123'
Taki
  • 17,320
  • 4
  • 26
  • 47

1 Answers1

1

The best way to do is just assigning the first value to the array:

var a = [['12ae11ee12-1bhb222','2019-10-10T19:46.19.632z','a123']];
a = a[0];
console.log(a);

But the right way of dealing it should be making sure that the endpoint or whatever that outputs should output correctly.

You can use Array.prototype.flat().

console.log([['12ae11ee12-1bhb222','2019-10-10T19:46.19.632z','a123']].flat());

This solution works if it's extremely nested too:

console.log([
  ['12ae11ee12-1bhb222'],
  ['2019-10-10T19:46.19.632z', 'a123']
].flat());
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252