Wednesday, November 25, 2015

Confused Array!!!!

Without much ado, let’s get to the code directly

var obj = [];
obj[ "a" ] = 10;
obj[ "b" ] = 20;
obj[ "c" ] = 30; 
console.log( obj.length );  // returns ZERO!!!

Experienced JS programmers would have seen the similar type of code, where in Array are being used as plain JS object and their response would just be – let’s fix this now!

The problem is the mixed usage which is possible cause of dynamic nature of the language. The usage in such a way does not cause any loss of data and you can just iterate it like a plain JS object as

for( var name in obj ){
   if( obj.hasOwnProperty( name ) ) {
      console.log( obj[name] );
// following works too.. 
console.log( obj["a"] );

Any usage with respect to Array API would do nothing such as

    console.log( "Array Length => "  + obj.length ); //returns ZERO, since array has no elements. "a"/"b"/"c" are properties of array object! 
    console.log( obj[1] ); //returns undefined, no element in array!

However in that case, why would choose to say that “obj” is any Array! It is not…


Router Password – Yet Another Problem

Recently, I had to replace my wireless router, LinkSys WRT54G2, with DLink DSL-2730U.  Obviously, when you replace router, you’ll have to re-setup configuration and that’s what I started with. DLink router configuration was seamless and since it has support for in-built ADSL modem, I could remove my good old beetel ADSL modem.

Configuration for ADSL is absolutely simple steps  if you have required information from your ISP. It worked immediately and I got connected through ethernet cable. After which I tried to configure wireless setup and tried to connect via wi-fi.  Instead all I got was

Connecting to DLink DSL Router

Whoa! It started with “Connecting… ” message and then the above and finally, it failed. Surprise surprise, I did not see any error.  Windows event log checked, router logs checked. Nothing anywhere. Now keep guessing.

Thinking that I probably made mistake while configuration,  I put the router back in factory default mode and restarted the configuration manually.  While doing so,  noticed that DLink configuration UI had absolutely no feedback mechanism to the user. You keep configuring and try to save. It just saves and keeps you in the same page. Whether the save succeeded or not, there was no message, indicator or any sort of thing.  May be they can improve things here.

Now, back to wireless configuration.  I sort of guessed that it may be related to security issue.  I tried running the wireless in no-authentication mechanism and it worked.

DLink DSL -2730U Wireless configuration

Re-enabled WPA2 with pre-shared key(wireless password), and it failed again.   Clueless, and with Google also not helping me here,  I was running out of ideas.

Not sure why, I thought of changing the password to a very simple one and tried with that. It WORKED!  What happened here?

Thinking that I would have changed something else, I reset the password to the previous one and of course, it failed.   Now it was pretty much clear that password is an issue here. (How can you guess the password requirement when there is nothing in the UI/manual?)

The reason, password had a “$” (dollar) symbol. Yes, you read it right! The actual issue was when your password for wireless configuration has “$” symbol, it simply fails. Remove the “$” symbol and it works.

For the record, I noted this issue on DLink – DSL-2730U with Firmware version IN_1.02.

DLink UI






Find Me!
View Kunal Kumar's profile on LinkedIn