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 -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -