Home > Enterprise >  why id is found at position 1 in str.indexof() in js
why id is found at position 1 in str.indexof() in js

Time:01-20

let str = 'Widget with id';

alert( str.indexOf('Widget') ); // 0, because 'Widget' is found at the beginning

alert( str.indexOf('widget') ); // -1, not found, the search is case-sensitive

alert( str.indexOf("id") ); // 1

CodePudding user response:

There is an "id" inside "Widget"

CodePudding user response:

Look closer to your string: "Widget with id"

  •  Tags:  
  • Related