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 -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -

What is happening when Matlab is starting a "parallel pool"? -