3

我有ToothSequence 一个包含所有整数类型值的数组

每当我想比较元素或添加整数时,我必须parseInt如图所示parseInt(ToothSequence[i]) + 1

 var ToothSequence = $("#hndBridge").val().split("|");
for (i = 1; i <= ToothSequence.length; i++) {
  if (parseInt(ToothSequence[i]) + 1 == parseInt(ToothSequence[i + 1]))
  {

是否可以在 jquery 中创建整数数组?如果不是请建议我

4

1 回答 1

6

You could do like this:

var ToothSequence = $("#hndBridge").val().split("|").map(function(e) { return +e; });

+e will convert e to a number.

--for old browser which Array doesn't have map method, use $.map instead--

var ToothSequence = $.map($("#hndBridge").val().split("|"), function(e) { return +e; });
于 2013-08-28T09:43:37.340 回答