7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【JavaScript】指定した文字列が配列の中の何番目に格納されているか表示する。

Last updated at Posted at 2014-01-06

こんにちは。

ちょっと無理くり学習したものを使ってみました。
function,if,forです。


var ary = ["a","b","c","d"] ;
var searchNum = "b" ;

function newFunk(){
    for(var i = 0 ; i < ary.length ; i++){
        if(searchNum === ary[i]){
            var num = i ;
            console.log(num) ;
        }
    }
}
newFunk() ; //1

最初に配列を定義して、キーワードを指定。
newFunkのなかで、配列をまわしてsearchNumとaryが合致した値を表示

何かもっと上手くやる方法あると思いますが
まずはfunctionに慣れていきたかった&期待の結果が得られたのでOKですかね・・。

それではこれからもよろしくお願いいたします。

7
7
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
7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?