【发布时间】:2019-01-13 20:51:12
【问题描述】:
如何使我的切片函数从某个单词而不是整数开始。这可能吗?
【问题讨论】:
标签: javascript html string slice
如何使我的切片函数从某个单词而不是整数开始。这可能吗?
【问题讨论】:
标签: javascript html string slice
使用indexOf,您可以找到单词或字母的索引并将其用作slice的begin参数
// The string to analyze
const str = 'I am a super cool monkey man'
// The word to find
const word = 'cool'
// The result
console.log(str.slice(str.indexOf(word)))
【讨论】: