var res = []; var color = ["red", "purple", "yellow", "green", "blue", "yellow", "purple"]; res[0] = color.indexOf("yellow"); // 진행방향 -> 2 res[1] = color.indexOf("black"); // 일치항목이 없음 -1 res[2] = color.lastIndexOf("yellow"); // 진행방향 <- 5 res[3] = color.lastIndexOf("yellow", 4); // blue부터 <- 2 for(var i in res) { document.write(res[i] + "<br>"); }