For..In loops in javascript - key value pairs
来源:互联网 发布:网络教育报考条件 编辑:程序博客网 时间:2024/06/13 09:41
http://stackoverflow.com/questions/7241878/for-in-loops-in-javascript-key-value-pairs
1. for(var key in dict)
for (var k in target){ if (target.hasOwnProperty(k)) { alert("Key is " + k + ", value is" + target[k]); }}
hasOwnProperty
is used to check if your target
really has that property, rather than having inherited it from its prototype. A bit simpler would be:
for (var k in target){ if (typeof target[k] !== 'function') { alert("Key is " + k + ", value is" + target[k]); }}
It just checks that k
is not a method (as if target
is array
you'll get a lot of methods alerted, e.g. indexOf
, push
, pop
,etc.)
Object.keys(obj).forEach(function (key) { // do something with obj[key]});
0 0
- For..In loops in javascript - key value pairs
- JavaScript探秘:for-in循环(for-in Loops)
- Loops in JavaScript
- Storing hundreds of millions of simple key-value pairs in Redis
- json对象结合for in,for in中遍历到的是json对象的key 而不是value
- The Loops in C#
- Object.key()与for...in...
- Performance comparison for loops of List in java
- For loops in R: how to do a “continue”
- [leetcode javascript解题]Swap Nodes in Pairs
- Pull error. No value for key branch.master.merge found in configuration
- egt、GetHub更新本地No value for key branch.master.merge found in configuration
- $Value{}ntException: Could not resolve placeholder 'KEY' in string value "${
- JavaScript For...In 声明
- JavaScript For...In
- JavaScript For...In 声明
- javascript - for in
- JavaScript for...in循环
- linux(ubuntu14.04)+GPU+cuda6.5+caffe+openCV2.4.9+matlab2014a+python的新手配置
- C语言中打开文件读取,写入的操作
- 猿团推出免费开发(成品)APP 助力移动互联网创业
- Fiddler(七) | QuickExec
- 图像处理-线性滤波-3 高斯滤波器
- For..In loops in javascript - key value pairs
- 【C++】:C++之函数模板
- 编译型语言与解释型语言的区别
- hibernate三种状态的demo
- MongoDB学习13_MongoDB学习笔记之 第4章 MongoDB整合Spring
- Msql练习(二)
- Android Drawable Resources系列4:<selector>
- pymssql的字符集问题
- 深入浅出RxJava(一:基础篇)