LoginSignup
0
0

indexOf の備忘録

Posted at

indexOfを使った時にエラーが出る

忘れがちなので、備忘録として記録です。

const str = 'tomato ha oishine!';
str.indexOf('tomato') // 結果:0
const str = undefined;
str.indexOf('tomato') // 結果:エラー

VM181:1 Uncaught TypeError: Cannot read properties of undefined (reading 'indexOf')

undefined(未定義)のプロパティは読み込めないよって言われる。

const str = null;
str.indexOf('tomato') // 結果:エラー

TypeError: Cannot read properties of null (reading 'indexOf')

nullのプロパティは読み込めないよって言われる。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0