of的用法总结

文章转自:https://wenku.baidu.com/view/99c92fde6f1aff00bed51ee5.html
版权归原作者!


词的用法分析原则一般是【词不离句】,即在具体语境中分析其用法。你没有提供语境,那就全面的学习一下of的用法吧。

of [ɔv; əv; v; f] prep.

  1. (属于)…的;
    the king of England英格兰国王

  2. 含有…的,装有…的:
    a book of pictures一本画册
    a glass of water一杯水

  3. 由…组成:
    a meal of bread and water只有面包和白开水的一顿饭

  4. 在…之中的:
    a member of the football team一名足球队员

  5. 由…制成:
    a bridge of wood一座木桥

  6. [表示日期、时间]
    the 2nd of June 6月2日
    It’s 10 (minutes) of 6.现在是6点差10分钟。

  7. [表示距离、方向、分隔、 离开等]:
    within half a mile of the park离公园半英里以内
    east of the city 城市以东

  8. [表示由来, 起源,出处]从, 来自…的:
    a girl of the nobility贵族小姐

  9. [表示原因、理由、动机等]由于,因为:
    to die of hunger死于饥饿

  10. [表示具有某种性质、状况]:
    a man of tact一个老练的人
    a plan of great decision一项重大决策

  11. [表示同位]
    the art of photo taking摄影艺术

  12. [表示相似]:
    the idiot of a brother那个白痴兄弟

  13. [表示数量或种类]:
    300 square metres of grass land 300平方米草坪
    colours of light五光十色的色彩

  14. [表示部分或全部]:
    one of us我们之中的一人
    the whole sum of ours我们所有的钱

  15. [表示动作的主体]
    the shooting of a football player足球运动员的射门

  16. [表示动作的对象]
    protection of natural circumstances保护自然环境

  17. [表示年龄或友谊关系等的持续时间]:
    a friend of 50 years有50年交情的老友

  18. 在…期间:
    He always likes to go swimming of an evening.他总喜欢晚上去游泳。

  19. [表示免除、剥夺等]:
    to cure him of a disease医好他的病

  20. 关于,与…有关:
    the talks of peace和谈
    the time of arrival到达的时间

  21. 用于…的:
    a day of rest休息日

  22. 对于, 由…感到(或作出的):
    one’s fear of an umbrella对雨伞的恐惧
    the whistling of a cold wind寒风的怒号

  23. 由…所著(或所作、所画等)的:
    the plays of Shakespeare莎士比亚的戏剧

  24. (艺术、文学作品等)以…为主题的:
    a painting of figure一幅人体画

  25. 在…处(或地方)的:
    a student of Harvard哈佛大学学生

  26. 在…方面:
    be fleet of foot走路快,捷足的

  27. 在…中较(或最)突出的:
    picture of pictures最好的图片

  28. 在…一方:
    It was very mean of you to hit your wife.你打妻子, 太卑鄙了。

  29. [用于表示厌烦、厌倦等的形容词之后]对…;对于;关于

  30. [古语]被(=by):
    to be consumed of worms被虫子吃掉了

  31. [古语]对着,向着

### JavaScript `indexOf` 方法的使用教程 #### 什么是 `indexOf`? `indexOf()` 是 JavaScript 中用于查找子字符串或数组元素的方法。对于字符串对象,它可以定位某个子字符串首次出现的位置;而对于数组对象(通过扩展原型实现),可以用来查找特定元素是否存在及其索引位置。 --- #### 字符串中的 `indexOf` ##### 基本语法 ```javascript str.indexOf(searchValue, fromIndex); ``` - **参数** - `searchValue`: 必需。要查找的子字符串。 - `fromIndex`: 可选。从哪个索引开始查找,默认为 0。 - **返回值** 返回第一个匹配项的索引位置,如果未找到则返回 `-1`[^2]。 ##### 示例代码 ```javascript let str = "This is a test string."; document.write(str.indexOf("is")); // 输出: 2 document.write("<br>"); document.write(str.indexOf("test", 5)); // 输出: 8 document.write("<br>"); document.write(str.indexOf("notfound")); // 输出: -1 ``` --- #### 数组中的 `indexOf` 虽然原生数组并没有内置支持 `indexOf` 的功能来查找复杂数据结构,但可以通过自定义方法或者现代浏览器的支持直接调用: ##### 基本语法 ```javascript array.indexOf(searchElement, fromIndex); ``` - **参数** - `searchElement`: 必需。要查找的数组元素。 - `fromIndex`: 可选。从哪个索引开始查找,默认为 0。 - **返回值** 同样返回第一个匹配项的索引位置,若不存在则返回 `-1`[^4]。 ##### 示例代码 ```javascript // 使用原生 Array.prototype.indexOf() let arr = [10, 20, 30, 40]; console.log(arr.indexOf(30)); // 输出: 2 console.log(arr.indexOf(50)); // 输出: -1 // 自定义 indexOf 实现 if (!Array.prototype.indexOf) { Array.prototype.indexOf = function (element) { for (let i = 0; i < this.length; i++) { if (this[i] === element) return i; } return -1; }; } let customArr = ["apple", "banana", "cherry"]; console.log(customArr.indexOf("banana")); // 输出: 1 ``` --- #### 特殊情况处理 当传入非法参数时的行为需要注意: - 如果 `fromIndex` 小于 0,则视为从头开始搜索; - 如果 `fromIndex` 大于等于字符串长度,则返回 `-1`。 示例: ```javascript let text = "abcdefg"; console.log(text.indexOf("a", -5)); // 输出: 0 (忽略负数) console.log(text.indexOf("z", 10)); // 输出: -1 (超出范围) ``` --- #### 总结 无论是字符串还是数组,`indexOf` 都是一个非常实用的基础工具函数,在日常开发中可以帮助快速判断目标值的存在性和具体位置。然而需要注意的是其区分大小写以及仅能检测单次匹配的特点[^1]^。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值