js中根据已知key得到某对象中相对应的value的方法

2023-12-25 14:43:22 浏览数 (1)

代码语言:javascript复制
    var key = "accountBingFlag1";var value = obj[key]; 
    var key = "accountBingFlag1";var value = eval("obj." key);

实例

代码语言:javascript复制
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>
	var bindingMessageVo={accountBingFlag1:"100",accountBingFlag2:"200",accountBingFlag3:"300"}
    for (var i=1;i<4;i  ){
        var accountBingFlag = "accountBingFlag"   [i];
        console.log(accountBingFlag);
		console.log(bindingMessageVo[accountBingFlag]);
		console.log(eval("bindingMessageVo." accountBingFlag))
    }
</script>
</html>

0 人点赞