for(var i in aArray) VS for(i=0; i<aArray.length; i++)

前端 未结 6 875
挽巷
挽巷 2021-01-07 10:20

I just want to ask if the in_array_orig and in_array_new is just the same. and also im confused on the result when comparing both array (<

6条回答
  •  情话喂你
    2021-01-07 10:43

    To your first question, pls refer http://www.openjs.com/articles/for_loop.php

    About the second:

    echo(in_array_orig(24, a)); // true
    echo(in_array_new(24, b)); // true
    

    I think this won't be a problem to you.

    echo(in_array_orig(aArr2, b));
    echo(in_array_new(aArr2, b));
    

    Both of these would definitely be false, becuz they are no where inside b. If you make a small change in b:

    var b = {0:aArr1, 1:24, 2:'manila', 3:[1]};
    

    then try this:

    console.log(in_array_new(aArr2, b[3]));
    console.log(in_array_orig(aArr2, b[3]));
    

    they are both True now.

    Finally, the last:

    echo ((aArr1==aArr2));
    

    "==" operator compares their value, so this is false because they clearly bears different content, meaning value.

    echo ((aArr1===aArr2));
    

    "===" compares their value and type, their values are different but their types are the same, you can check it by:

    console.log(typeof aArr1===typeof aArr2);
    

    thus it is still a False.

提交回复
热议问题