49

Can someone tell me since which ECMA version the IN operator is available and which browsers (versions) support it ?

Explanation:

The IN-operator can be used like the following:

var myObject = {
    Firstname: 'Foo',
    Lastname: 'Bar'
};

if('Lastname' in myObject){
    // Lastname is an attribute of myObject
}
0

2 Answers 2

56

It is defined in ECMAScript 3rd edition. It is available in IE 5.5+ and all in-use versions of Firefox, Chrome, Opera and Safari.

You can use it safe in the knowledge that it will work.

You should err on the side of caution when using it to check event support. All implementations except older Firefox versions support "eventname" in element as a test for DOM events.

"onclick" in document.body; // -> false in old Fx, true in others
document.body.setAttribute("onclick", "");
typeof(document.body.onclick == "function"); // -> true in Fx
Sign up to request clarification or add additional context in comments.

7 Comments

It's only in IE 5.5+; IE 5.0 was the ‘problem browser’ for in, though obviously that worry is long gone now.
@Nick: it certainly is in 3.0, even though IE didn't support it at the time of publication. ECMAScript 3.1 was the development name for what became the Fifth Edition.
@bobince - You're indeed right, I had the 2nd edition, not the 3rd up when comparing and couldn't find section 11.8.7, it is in 3.0.
@Andy: you're right, that doc is indeed nonsense! I've got IE5/Win98 here and in definitely doesn't work.
|
2

According to MDC, it's implemented in JavaScript 1.4.

According to Wikipedia:

  • Netscape Navigator 6.0
  • Firefox 1.0+
  • IE 5.5+
  • Opera 6.0+
  • Safari 3.0+
  • Chrome 1.0+

So I think you're probably OK :)

4 Comments

because I can do undefined = 'defined!'; earlier in the code, which is obviously beneficial.
Really, you should have put that as another answer, as now our comments make no sense.
@Skilldrick you can strikeout text in an answer using the <s> tag apparently meta.stackexchange.com/questions/63768/…
note: I doubt Wikipedia is a reliable source regarding Javascript features browser versions support.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.