0
RatecardIDs=[2, 22, 23, 25];
 if (parseInt(cellValue) in (RatecardIDs)) {
}

How I can use In operator in if condition. in this code firs time it will execute code in if block then it is executing false block.

1
  • 1
    use Array.indexOf() - if(RatecardIDs.indexOf(parseInt(cellValue)) > -1) Commented Aug 12, 2014 at 13:42

2 Answers 2

4

The in operator in javascript is for key's in objects.

You can use Array.indexOf() to check if an element exists in the array, it will return -1 if it doesn't exist

Now,

You can check if(RatecardIDs.indexOf(parseInt(cellValue))>-1) {...}

Sign up to request clarification or add additional context in comments.

Comments

1

In javascript in operator used to get keys in an object. You can use javascript's Array.indexOf or jquery's inArray for that.

Just use like bellow

RatecardIDs=[2, 22, 23, 25];

if(RatecardIDs.indexOf(parseInt(cellValue))>-1){
 ...
}

Or using jquery

if($.inArray(parseInt(cellValue),RatecardsId)>-1){
  ....
}

1 Comment

@ChiragSutariya I don't see a problem in that answer, where is the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.