js检查字符串是否存在数组中,js判断字符串是否存在
作者:
可乐_加冰_ | 来源:发表于
2024-06-29 11:03 被阅读0次
let arrayOfObjects = [
{ id: '1', name: 'Alice' },
{ id: '2', name: 'Bob' },
{ id: '3', name: 'Charlie' }
];
let valueToCheck = 'Bob';
let exists = arrayOfObjects.some(obj => obj.name === valueToCheck);
console.log(exists); // 输出: true
let arrayOfStrings = ['Alice', 'Bob', 'Charlie'];
let valueToCheck = 'Bob';
let exists = arrayOfStrings.includes(valueToCheck);
console.log(exists); // 输出: true
本文标题:js检查字符串是否存在数组中,js判断字符串是否存在
本文链接:https://www.haomeiwen.com/subject/bbkucjtx.html
网友评论