Replace Problem - Printable Version -Shoutbox (https://shoutbox.menthix.net) +-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58) +--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4) +---- Forum: Scripting (/forumdisplay.php?fid=39) +----- Thread: Replace Problem (/showthread.php?tid=98078) Replace Problem by Spunky on 08-02-2011 at 08:21 PM
I'm having trouble with the following code: js code: If x[0] is set to "push", "join", "reverse", "pop" or any other array method then I get "Object Expected" error and it traces: quote: Any ideas why? Everything should just be treated as a string I'm probably being stupid RE: Replace Problem by matty on 08-02-2011 at 08:33 PM Couldn't you use .toString()? RE: Replace Problem by Spunky on 08-02-2011 at 08:36 PM Doesn't work. I get the same results RE: Replace Problem by Eljay on 08-02-2011 at 08:48 PM
How was y defined? RE: Replace Problem by whiz on 08-02-2011 at 08:48 PM
I'm assuming it's because, for objects, foo.bar is the same as foo["bar"]. Seems calling []["foo"], where foo is an array method, always seems to do this. RE: Replace Problem by Spunky on 08-02-2011 at 08:52 PM
quote: I'll try shortly. If that does fix it, it's a bit sloppy, but I want it working. For the purposes of the script, it doesn't really cause any errors, Just don't want all that in the debug =/ EDIT: Nope can't seem to do that without breaking the script. I need the value related to x[0] from y quote: Arrays are Objects RE: Replace Problem by Eljay on 08-02-2011 at 09:00 PM
quote: Well yeah, but the in keyword returns true because of all the built-in Array functions. Try using: js code: ??? RE: Replace Problem by Spunky on 08-02-2011 at 09:02 PM Works perfect No dodgy try... catch statements for me RE: Replace Problem by Matti on 08-03-2011 at 08:50 AM
How is y defined? If you're storing values in an Array variable using string keys, then you're storing them as properties in the Object and not as elements in the Array. js code:If you don't need any of the Array features such as .length, .pop() or .slice(), simply make it an Object: js code:That way, you don't need any of those .hasOwnProperty() checks to skip any unwanted methods from the prototype, since Object.prototype should be empty. It'd also help if you gave your variables decent names. How will you know what x[0] and y were when you look at your code again in a few months? |