gw1500se Posted July 14, 2020 Share Posted July 14, 2020 I have the following javascript that I am trying to reverse engineer: function set_sw(row) { var i; var ofs = ofs_sr + row * 6; var sel_var = document.forms[0].elements[ofs + 5]; // Use the sw_id table to get the ID and the user-friendly name sel_var.options[0] = new Option("None", "None", false); for (i = 0; i < sw_id.length; i += 2) { sel_var.options[i/2+1]=new Option(sw_id[i+1], sw_id[i], false); } // Set the option if (sel[row * 2 + 1] == "") { sel_var.selectedIndex = 0; return; } for (i = 0; i < sw_id.length; i += 2) { if (sel[row * 2 + 1] == sw_id[i]) { sel_var.selectedIndex = i/2 + 1; return; } } } My question is how the array 'sel' is being used? That array appears to be used as pairs of values. var sel = [0,"170000001A5EA905",0,"910000001A7F2A05"]; var sw_id = ["910000001A7F2A05","910000001A7F2A05","170000001A5EA905","Test"]; I am trying to understand where/how the first element of each pair is being used. It appears to me that it is not used but it seems strange then that it is there. I'm hoping some new eyes can help. Can someone tell me if and where it is being used in that script? TIA. Quote Link to comment https://forums.phpfreaks.com/topic/311088-reverse-engineering-a-javascript/ Share on other sites More sharing options...
kicken Posted July 14, 2020 Share Posted July 14, 2020 36 minutes ago, gw1500se said: It appears to me that it is not used but it seems strange then that it is there. It doesn't appear to be used. It might just be there for consistency sake with the sw_id array. If both array's are auto-generated somewhere than it might have just been easier to keep two lists of pairs and dump them to an array rather than one list of pairs and one list of values only. I would have just written this to use either a 2d array or array of objects rather than this flattened array approach. It's unnecessarily hard to understand as written. Quote Link to comment https://forums.phpfreaks.com/topic/311088-reverse-engineering-a-javascript/#findComment-1579628 Share on other sites More sharing options...
gw1500se Posted July 14, 2020 Author Share Posted July 14, 2020 Thanks for confirming my theory. Quote Link to comment https://forums.phpfreaks.com/topic/311088-reverse-engineering-a-javascript/#findComment-1579630 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.