Home  >  Article  >  Web Front-end  >  Javascript traverses sub-objects in an object_javascript tips

Javascript traverses sub-objects in an object_javascript tips

WBOY
WBOYOriginal
2016-05-16 18:50:431324browse
Copy code The code is as follows:

var json_obj = {
pos1:{x1:123, x2 :234, y1:222, y2:333},
pos2:{x1:999, x2: 888, y1:777, y2:666}
};
for (var p in json_obj) {
alert(json_obj[p].x1);
}

This method can also be extended, such as traversing the attributes in the object, functions in the object, etc.
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