0

I am having a string - Item 1 , need to convert it into an array

I have tried the following -

var demo = "Item 1"
let array = [demo]
console.log(array);

this gives me the following result on console -

0: "1"
1: "Item"
2: "Item 1"
length: 3
[[Prototype]]: Array(0)

expected result:

0: "Item 1"
length: 1
[[Prototype]]: Array(0)
VLAZ
  • 26,331
  • 9
  • 49
  • 67
yash28
  • 1
  • The code you have is correct. The result you see must come from something else updating the array *after* this code and *before* you examine it in the browser console. There is no way otherwise for wrapping a string in an array to randomly produce three items. – VLAZ Apr 03 '23 at 05:27

0 Answers0