关于html:第-46-题如何判断一个字符串对象数组中是否包含某个值

1次阅读

共计 482 个字符,预计需要花费 2 分钟才能阅读完成。

字符串

let str = 'abdefgh';

console.log(str.indexOf('d') > -1); // true
console.log(str.search('d') > -1); // true
console.log(/d/.test(str)); // true

对象

let obj = {age: 20};

console.log(obj.age) // 20
console.log(obj.hasOwnProperty('age')); // true

数组

let arr = ['a', 'b', 'c', 'd'];

console.log(arr.indexOf('d') > -1); // true
console.log(arr.includes('d')); // true

文章的内容 / 灵感都从下方内容中借鉴

  • 【继续保护 / 更新 500+ 前端面试题 / 笔记】https://github.com/noxussj/In…
  • 【大数据可视化图表插件】https://www.npmjs.com/package…
  • 【利用 THREE.JS 实现 3D 城市建模(珠海市)】https://3d.noxussj.top/
正文完
 0