Simon Willison’s Weblog

Subscribe

1 item tagged “arrays”

2009

instanceof considered harmful (or how to write a robust isArray. JavaScript’s instanceof operator breaks when dealing with objects that may have been created in a different document or frame, since constructors are unique to each frame. Instead, you can check for arrays using the default Object.toString method which the JS spec guarantees will return [object Array]. # 12th January 2009, 10:55 am