a = ["USAGE", "SELECT", "ALTER"]; b = [ { name: "ALTER",},{name: "LOCK TABLES",},{name: "SELECT",},]; 使用js判断a数组值和数组b的name值是否相同
时间: 2024-04-14 07:23:48 浏览: 35
你可以使用JavaScript中的循环和条件语句来判断数组a的值和数组b的name值是否相同。以下是一种可能的实现方式:
```javascript
// 判断a数组值和数组b的name值是否相同
function checkValues(a, b) {
for (let i = 0; i < a.length; i++) {
let found = false;
for (let j = 0; j < b.length; j++) {
if (a[i] === b[j].name) {
found = true;
break;
}
}
if (!found) {
return false;
}
}
return true;
}
// 测试
const a = ["USAGE", "SELECT", "ALTER"];
const b = [
{ name: "ALTER" },
{ name: "LOCK TABLES" },
{ name: "SELECT" },
];
const result = checkValues(a, b);
console.log(result); // 输出 true
```
阅读全文