【问题标题】:Javascript slice method, start at a certain word.s [duplicate]Javascript切片方法,从某个word.s开始[重复]
【发布时间】:2019-01-13 20:51:12
【问题描述】:

如何使我的切片函数从某个单词而不是整数开始。这可能吗?

【问题讨论】:

    标签: javascript html string slice


    【解决方案1】:

    使用indexOf,您可以找到单词或字母的索引并将其用作slicebegin参数

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

    【讨论】:

    • 我想知道为什么这会被否决
    • 可能是因为重复...
    猜你喜欢
    • 1970-01-01
    • 2011-06-13
    • 2016-03-02
    • 2021-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-05
    • 1970-01-01
    相关资源
    最近更新 更多