Home  >  Article  >  Web Front-end  >  Analysis of usage of in operator in javascript_javascript skills

Analysis of usage of in operator in javascript_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:01:461148browse

The example in this article describes the usage of in operator in javascript. Share it with everyone for your reference. The specific analysis is as follows:

The

in operator hopes that its left operand is a string or can be converted to a string, and that its right operand is an object; if the right-hand object has an attribute name named the left operand value, then the expression The formula returns true:

var point = {x:1,y:1};
"x" in point //true
"z" in point //false
"toString" in point //true
var ary = [1,2,3];
"0" in ary; //true,ary含有索引0("0"回转换为0);
1 in ary;  //true,ary含有索引1
3 in ary;  //false

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn