What is the difference between slice() and substr() in JavaScript?

后端 未结 5 1132
轮回少年
轮回少年 2020-12-31 04:34

Can I ask what the difference is between string object slice() and substr() in JavaScript?

5条回答
  •  臣服心动
    2020-12-31 05:15

    I think the difference between str.slice() and str.substr() is the second parameter:

    .slice() takes EndIndex while .substr() takes length as in:

    .slice(StartIndex,EndIndex) and .substr(StartIndex,length).

提交回复
热议问题