+ 1
Remove the [] from given Array in Javascript?
One MNC Interviewer asked this question Var a = [1,[2,3],4] but we need output is [1,2,3,4]...Please someone explain how to remove the [] inbetween the given Array in Javascript
4 Respuestas
+ 8
Array.prototype.flat()
the flat() method reduces multidimensional arrays to just...1
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat
+ 5
Use :
a= [].concat(...a); //Flats one dimension
Brains🇳🇬 cant find Array.prototype.flatten 😐
Mohamed ELomari I don't think the interviewer would be asking him about a Stage 3 ES10/ES2019 proposal.
+ 1
Thank you