let text = "docker run -d -p 8080:8080 -p 8081:8081 -p 8081:8081 -p 8081:8081 -P 8082 -P 8082 -e key1=value1 -e key2=value23 -e key3 value3" let array1 = findStringIndex(text, " -p "); let array2 = findStringIndex(text, " -P "); let array3 = findStringIndex(text, " -e "); function findStringIndex(text1, text2) { let array = []; let index = text1.indexOf(text2); while (index !== -1) { array.push(index); index = text1.indexOf(text2, index + 1); } return array; }
indexOf
相關文章
- indexOf()的用法Index
- JavaScript 字串 indexOf()JavaScript字串Index
- JavaScript 字串indexOf()JavaScript字串Index
- JavaScript 陣列 indexOf()JavaScript陣列Index
- JavaScript 陣列indexOf()JavaScript陣列Index
- Js中的find,findIndex,indexof,includesJSIndex
- indexOf原理,Java,javascript,python實現IndexJavaScriptPython
- 演算法:indexOf陣列去重演算法Index陣列
- 相容所有瀏覽器array物件indexOf()方法瀏覽器物件Index
- jquery-3.4.1.js:10091 Uncaught TypeError: url.indexOf is not a functionjQueryJSErrorIndexFunction
- 關於String內的indexOf方法的一些疑問Index