编程语言/Json/获取随即JSON对象:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
第36行: 第36行:


== hasOwnProperty ==
== hasOwnProperty ==
1:获得 JSON 随机对象
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
function randomProperty (obj) {
function randomProperty (obj) {
第46行: 第47行:
     return keys[keys.length * Math.random() << 0];
     return keys[keys.length * Math.random() << 0];
}
}
randomProperty(obj);</syntaxhighlight>
randomProperty(obj);
==> "b"</syntaxhighlight>