var arr1 = ['tokyo','nagoya','osaka','fukuoka']; document.write( '配列<br>' + arr1.indexOf('nagoya') + '<br>' + arr1.indexOf('fukuoka') + '<br>' + arr1.indexOf('tokyo') + '<br>' + arr1.indexOf('osaka') + '<br>' ); var arr2 = 'tokyo,nagoya,osaka,fukuoka'; document.write( '文字列<br>' + arr2.indexOf('nagoya') + '<br>' + arr2.indexOf('fukuoka') + '<br>' + arr2.indexOf('tokyo') + '<br>' + arr2.indexOf('osaka') + '<br>' );
See the Pen js: Array.prototype.indexOf() by nwstcode (@nwst) on CodePen.