0
id="+strength.cat_id+","+strength.sub_cat_id+"

the id will be like this id=4,20

$("#weakTable").on('click', '.skillTestRemider', function () {
var skillTetCatAndSubCat = $(this).attr('id');

in this variable, i have a string like this 4,20 in this 4 is a category and 20 is a subcategory.

I want to split up as diff variables like shown below. how can I do that..?

var cat = 4
var subcat = 20
Mr world wide
  • 4,696
  • 7
  • 43
  • 97
  • 1
    [split](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split) – empiric Jun 01 '17 at 17:17

1 Answers1

1

Use String#split method for that.

var spl = skillTetCatAndSubCat.split(',');
var cat = spl[0];
var subcat = spl[1];

var skillTetCatAndSubCat = '4,20';
var spl = skillTetCatAndSubCat.split(',');
var cat = spl[0];
var subcat = spl[1];

console.log(cat, subcat);
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188