首页 > 开发 > JS > 正文

js简单遍历获取对象中的属性值的方法示例

2024-05-06 16:52:25
字体:
来源:转载
供稿:网友

本文实例讲述了js简单遍历获取对象中的属性值的方法。分享给大家供大家参考,具体如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>www.vevb.com JS遍历json属性值</title></head><body><script>//  js获取对象中的属性值  var slideArray = { slides: [    { "imgsrc": "a.jpg", "url": "", "alt": "这是a图片" },    { "imgsrc": "b.jpg", "url": "", "alt" : "这是b图片" },    { "imgsrc": "c.jpg", "url": "", "alt": "这是c图片" },    { "imgsrc": "d.jpg", "url": "", "alt": "这是d图片" },    { "imgsrc": "e.jpg", "url": "", "alt" : "这是e图片" }]  };  //通过以下的方法可以遍历js数组中对象的属性  for(var i=0; i<slideArray.slides.length; i++) {    console.log(slideArray.slides[i].imgsrc);  }</script></body></html>

希望本文所述对大家JavaScript程序设计有所帮助。


注:相关教程知识阅读请移步到JavaScript/Ajax教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表