0

I wanted if the arr is true alert true if not alert false. Where I actually making mistake I checked my code at jslint but I found only alert was used before it was defined. Thank you

var arr = [1,23,4,5];
if(arr.isArray()===-1){
 alert(' false ');
}else{
  alert(' true ');
}

3 Answers 3

1

You need to use:

if(!$.isArray(arr)){

instead of:

if(arr.isArray()===-1){

since $.isArray() take an argument which is an object to determine whether that object is an array or not:

var arr = [1, 23, 4, 5];
if (!$.isArray(arr)) {
    alert(' false ');
} else {
    alert(' true ');
}

Fiddle Demo

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

Comments

0

isArray is return boolean value. Compare with false.

   var arr = [1,23,4,5];
    if(arr.isArray()===false){
     alert(' false ');
    }else{
      alert(' true ');
    }

OR simple

var arr = [1,23,4,5];
alert(arr.isArray());

Comments

0

$.isArray(arr) See below link

http://api.jquery.com/jquery.isarray/

Comments

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.