javascript - Is there a way to clip a string in a jquery function? -


im new jquery im using following code:

var lineparts = []; $.each( chartdata, function(k,v){ barparts.push({     label: k,     value: v   }); }); 

how clip k first 3 characters of string? example want positive become pos. ive tried using no joy:

var lineparts = []; $.each( chartdata, function(k,v){ k = k.substring(0,3); lineparts.push({     label: k,     value: v   }); }); 

you have mistaken function(k, v). should function(v,k),i.e (value, key)

var lineparts = [];  var chartdata = ['positive','negative'];  $.each( chartdata, function(v,k){  k = k.substring(0,3);  lineparts.push({      label: k,      value: v    });  });    console.log(lineparts);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -