I have a JavaScript object like the following:
(我有一个如下的JavaScript对象:)
var p = {
"p1": "value1",
"p2": "value2",
"p3": "value3"
};
Now I want to loop through all p
elements ( p1
, p2
, p3
...) And get their keys and values.
(现在,我想遍历所有p
元素( p1
, p2
, p3
...),并获取它们的键和值。)
How can I do that? (我怎样才能做到这一点?)
I can modify the JavaScript object if necessary.
(我可以根据需要修改JavaScript对象。)
My ultimate goal is to loop through some key value pairs and if possible I want to avoid using eval
. (我的最终目标是遍历一些键值对,如果可能的话,我想避免使用eval
。)
ask by Tanmoy translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…