javascript - access elements in array of strings that contain certain strings - i have array can this: ["whatwp", "isvbz", "thedt", "temperaturenn", "inin", "bostonnn"] i want access element containing in, if exists , next elements(s) until reach , including element nn in it. , bring together elements string. when seek access element containing in so, -1 there no element containing in. here's how trying it: strarr = ["whatwp", "isvbz", "thedt", "temperaturenn", "inin", "bostonnn"]; strarr[strarr.indexof('in')]; but undefined because nil @ -1 exists. how can access element of array of strings if contains in , every element after until matches element containing nn, including element? , joining string? you need loop that: var strarr = ["whatwp", "isvbz", "thedt", "temperaturenn", "i