Search code examples
javascriptangularjslodashramda.js

JavaScript: Convert string to array


I have an array :

itemSku = ["MY_SERVICE","SKU_A","SKU_B"];

Now I'm passing this value to a component in Angular. There I check the type of the itemSku and it is returning a string, so I am not able to perform array operations on this.

console.log(typeof itemSku);
*string*

How can I convert this back to an array? I'm not allowed to use jquery but can use Javascript, Ramda or Lodash


Solution

  • You can use JSON.parse(itemSKu) to convert it back to array