-4
var string = "Chemistry,English,History"; 

Sir i want to convert it to an array like:

var subjects= ["Chemistry","English","History"]; 

using jQuery

guradio
  • 15,524
  • 4
  • 36
  • 57
Muzzamil Rasool
  • 21
  • 1
  • 1
  • 2
  • Use `split`. `string.split(",")` – gurvinder372 Mar 15 '18 at 12:50
  • 1
    Please in future, try to articulate a proper question and don't just copy + paste one sentence into title and text. – Vulpex Mar 15 '18 at 12:52
  • 1
    Welcome to SO! Please take the [tour](https://stackoverflow.com/tour) and read through the [help center](https://stackoverflow.com/help), in particular *[How do I ask a good question?](https://stackoverflow.com/help/how-to-ask)* Do your research, [search](https://stackoverflow.com/help/searching) for related topics on SO, and give it a go. If you get stuck and can't get unstuck after doing more research and searching, post a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) of your attempt and say specifically where you're stuck. People will be glad to help. – Ele Mar 15 '18 at 12:52
  • 1
    There's no jquery here. – freedomn-m Mar 15 '18 at 12:59
  • should we remove the tag? – guradio Mar 15 '18 at 13:00

1 Answers1

2

No need of jquery. Just use .split() function to achieve this.

let string = 'Chemistry,English,History';
let arr = string.split(',');
console.log(arr)
Ishwar Patil
  • 1,671
  • 3
  • 11
  • 19