[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Errors/in_operator_no_object [Back]  [Original]

TypeError: cannot use 'in' operator to search for 'x' in 'y'( 'in' 'x' 'y') - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

TypeError: cannot use 'in' operator to search for 'x' in 'y'( 'in' 'x' 'y')

TypeError:    "in" (edge)
TypeError:   'in'   ,  'x' (Firefox)
TypeError:    'in'   'x'  'y' (Firefox, Chrome)

In this article

TypeError

?

in . , .

(, Python), in .

js
"Hello" in "Hello World";
// TypeError: cannot use 'in' operator to search for 'Hello' in 'Hello World'

String.prototype.indexOf()

js
"Hello World".indexOf("Hello") !== -1;
// true

null undefined

, , , null undefined.

js
var foo = null;
"bar" in foo;
// TypeError:     'in'   'bar'  'foo' (Chrome)
// TypeError:   'in'   ,  null (Firefox)

in .

js
var foo = { baz: "bar" };
"bar" in foo; // false

"PI" in Math; // true
"pi" in Math; // false

Array . the in , .

js
var trees = ["redwood", "bay", "cedar", "oak", "maple"];
3 in trees; // true
"oak" in trees; // false


Web Proxy Viewer  |  New URL  |  Original Page