没有合适的资源?快使用搜索试试~ 我知道了~
javascript遍历json对象的key和任意js对象属性实例
5 下载量 126 浏览量
2020-10-20
05:56:25
上传
评论
收藏 30KB PDF 举报
温馨提示


试读
1页
下面小编就为大家带来一篇javascript遍历json对象的key和任意js对象属性实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
资源推荐
资源详情
资源评论


















javascript遍历遍历json对象的对象的key和任意和任意js对象属性实例对象属性实例
下面小编就为大家带来一篇javascript遍历json对象的key和任意js对象属性实例。小编觉得挺不错的,现在就分
享给大家,也给大家做个参考。一起跟随小编过来看看吧
使用使用 keys 方法获取该对象的属性和方法:方法获取该对象的属性和方法:
function Pasta(grain, width, shape) {
this.grain = grain;
this.width = width;
this.shape = shape;
this.toString = function () {
return (this.grain + ", " + this.width + ", " + this.shape);
}
}
var spaghetti = new Pasta("wheat", 0.2, "circle");
var arr = Object.keys(spaghetti);
document.write(arr);
结果图:
显示 Pasta 对象中以字母“g”开头的所有可枚举属性的名称:
function Pasta(grain, width, shape) {
this.grain = grain;
this.width = width;
this.shape = shape;
}
function CheckKey(value) {
var firstChar = value.substr(0, 1);
if (firstChar.toLowerCase() == "g") {
return true;
} else {
return false;
}
}
var polenta = new Pasta("corn", 1, "mush");
var keys = Object.keys(polenta).filter(CheckKey);
document.write(keys);
结果如图:
遍历json对象的键:
var an_obj = { 100: 'a', 2: 'b', 7: 'c', "name": "wu", "interesting": "Game" };
document.write(Object.keys(an_obj));
结果如图:
以上这篇javascript遍历json对象的key和任意js对象属性实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也
希望大家多多支持我们。
资源评论


weixin_38686658
- 粉丝: 4
- 资源: 915
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


安全验证
文档复制为VIP权益,开通VIP直接复制
