gpt4 book ai didi

javascript - lastIndexOf 的默认值是多少?

转载 作者:行者123 更新时间:2023-12-02 19:50:46 25 4
gpt4 key购买 nike

string.lastIndexOf(searchValue[, fromIndex])

MDNfromIndex 默认值等于 string.length,但是,我真的认为它是 string.length-1

但我怎么想并不重要...我需要有人确认 fromIndex 的默认值是什么

他们是这么说的:

"It can be any integer between 0 and the length of the string. The default value is the length of the string."

最佳答案

根据 ECMAScript 5,它将是字符串的长度

15.5.4.8 String.prototype.lastIndexOf (searchString, position)

If position is undefined, the length of the String value is assumed, so as to search all of the String.

...

  1. Call CheckObjectCoercible passing the this value as its argument.
  2. Let S be the result of calling ToString, giving it the this value as its argument.
  3. Let searchStr be ToString(searchString).
  4. Let numPos be ToNumber(position). (If position is undefined, this step produces the value NaN).
  5. If numPos is NaN, let pos be +∞; otherwise, let pos be ToInteger(numPos).
  6. Let len be the number of characters in S.
  7. Let start min(max(pos, 0), len).
  8. Let searchLen be the number of characters in searchStr.
  9. Return the largest possible nonnegative integer k not larger than start such that k+ searchLen is not greater than len, and for all nonnegative integers j less than searchLen, the character at position k+j of S is the same as the character at position j of searchStr; but if there is no such integer k, then return the value -1.

关于javascript - lastIndexOf 的默认值是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9337795/

25 4 0
文章推荐: python-3.x - 谷歌云pubsub python同步拉取
文章推荐: mysql-workbench - 无法获取表 - 加载架构内容时出错
文章推荐: graphql - 如何使用 Nuxt ServerMiddleware 和 Apollo GraphQL 处理 301 重定向
文章推荐: javascript - 如何获得 4
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com