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

Sir i want to convert it to an array like:

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

using jQuery

5
  • Use split. string.split(",") Commented Mar 15, 2018 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. Commented Mar 15, 2018 at 12:52
  • 1
    Welcome to SO! Please take the tour and read through the help center, in particular How do I ask a good question? Do your research, search 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 of your attempt and say specifically where you're stuck. People will be glad to help. Commented Mar 15, 2018 at 12:52
  • 1
    There's no jquery here. Commented Mar 15, 2018 at 12:59
  • should we remove the tag? Commented Mar 15, 2018 at 13:00

1 Answer 1

2

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

let string = 'Chemistry,English,History';
let arr = string.split(',');
console.log(arr)

Sign up to request clarification or add additional context in comments.

2 Comments

i got it .Thanks
welcome Muzzamil. Do accept the answer if this has helped you. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.