admin管理员组文章数量:1314833
HI All,
In my js file i am getting an array of records (negetive values ) like this
deletedDetailIds = $.map(eformDetailIds, function(e) { return e < 0 ? e : null; });
For example the deletedDetailIds = -1234,-1235,-1256 like this.
Now i have to create an array and add these values with out negetive symbols. like
newArray = 1234,1235,1256.
Please help me in this
HI All,
In my js file i am getting an array of records (negetive values ) like this
deletedDetailIds = $.map(eformDetailIds, function(e) { return e < 0 ? e : null; });
For example the deletedDetailIds = -1234,-1235,-1256 like this.
Now i have to create an array and add these values with out negetive symbols. like
newArray = 1234,1235,1256.
Please help me in this
Share Improve this question asked Jun 1, 2011 at 19:34 SatyaSatya 5254 gold badges14 silver badges27 bronze badges 09 Answers
Reset to default 6The correct way would be to use Math.abs
:
$.map(eformDetailIds, function(e) {
return e < 0 ? Math.abs(e) : null;
});
You could also multiply with -1
.
You are dealing with numbers. Only the string representation contains a -
to indicate the negative value, so you cannot really remove the first character here.
Easy solution is multiply the values by -1 which make value + for you
example
var a = -12345 * -1;
a = 12345;
try this:
deletedDetailIds = $.map(eformDetailIds, function(e) { return e < 0 ? Math.abs(e) : null; });
Is this what you're looking for?
deletedDetailIds = $.map(eformDetailIds, function(e) {
return e < 0 ? Math.abs(e) : null;
})
if u are willing for replace -ve symbol then,
deletedDetailIds.replace(/-/g, "");
Use abs:
So Math.abs(number)
Where number will be the negative number
Try this
deletedDetailIds = $.map(eformDetailIds, function(e) { return e < 0 ? e : null; });
var total = 0;
$.each(deletedDetailIds, function(a, b){
total += Math.abs(b)
});
var deletedDetailIds = $.map(eformDetailIds,
function(item) { return item < 0 ? -item : null; }
);
Use the Math.abs function:
$.map(eformDetailIds, function(e) {
return e && e < 0 ? Math.abs(e) : 0;
});
More info here
本文标签: javascriptHow to remove the first character of a variableStack Overflow
版权声明:本文标题:javascript - How to remove the first character of a variable - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741972344a2407916.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论