4 回答
TA贡献1875条经验 获得超5个赞
var aa = function(arr,objArr){
for(let i=0;i<objArr.length;i++){
for(let o in objArr[i]){
if(objArr[i][o]===arr){
console.log(objArr[i]['def'])
}
}
}
}
aa(arr[0],objArr)
TA贡献1893条经验 获得超10个赞
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
var arr = [0,1,2,3];
var objArr = [
{abc:0,def:'你'},
{abc:1,def:'我'},
{abc:2,def:'他'},
{abc:3,def:'它'}
];
function checkFn(num) {
objArr.forEach(function(item){
if(item.abc == arr[num]){
console.log(item.def);
}
})
}
checkFn(0); // checkFn(0) ==> '你'
</script>
</body>
</html>
TA贡献1818条经验 获得超8个赞
arr.forEach((key,index) => {
objArr.forEach(item => {
if(item.abc === key) {
arr[index] = item.def
}
})
})
console.log('arr[0]',arr[0])
添加回答
举报