js array contains All In One
js array contains All In One
includes & contains & has
Array.prototype.contains
"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2020-10-01
* @modified
*
* @description Array.prototype.contains
* @difficulty Easy Medium Hard
* @complexity O(n)
* @augments
* @example
* @link
* @solutions
*
* @best_solutions
*
*/
const log = console.log;
Array.prototype.contains = function (key) {
// log(`\nthis`, this, this.length);
// for (let item in this) {
for (let item of this) {
// log(`item =,`, item);
// log(`key =`, key);
// if (item == key) {
// if (item === key) {
// type checker Object.prototype.toString()
// log(`JSON.stringify(item) === JSON.stringify(key)`, JSON.stringify(item) , JSON.stringify(key));
if (JSON.stringify(item) === JSON.stringify(key)) {
// break;
return true;
} else {
// continue;
}
}
return false;
}
const arr = [1, "3", {}];
const test = arr.contains("abc");
const test1 = arr.contains("3");
const test2 = arr.contains({});
log(`test =`, test)
log(`test1 =`, test1)
log(`test2 =`, test2)
/*
test = false
test1 = true
test2 = false
*/
/*
test = false
test1 = true
test2 = true
*/
覆盖 prototype 方法
扩展 prototype 方法
contains
https://developer.mozilla.org/en-US/docs/Web/API/Node/contains
https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/contains
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/permissions/contains
css contain
https://developer.mozilla.org/en-US/docs/Web/CSS/contain
/* Keyword values */
contain: none;
contain: strict;
contain: content;
contain: size;
contain: layout;
contain: style;
contain: paint;
/* Multiple keywords */
contain: size paint;
contain: size layout paint;
/* Global values */
contain: inherit;
contain: initial;
contain: unset;
布局优化,性能优化, 重绘重排
https://drafts.csswg.org/css-contain-1/
hasOwnProperty
has
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
refs
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes
https://www.w3schools.com/jsref/jsref_includes_array.asp#:~:text=The includes() method determines,()%20method%20is%20case%20sensitive.
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
js array contains All In One的更多相关文章
- js Array数组的使用
js Array数组的使用 Array是javascript中的一个事先定义好的对象(也可以称作一个类),可以直接使用 创建Array对象 var array=new Array(): 创建指定元 ...
- 从Chrome源码看JS Array的实现
.aligncenter { clear: both; display: block; margin-left: auto; margin-right: auto } .crayon-line spa ...
- js Array 方法总结
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- js & array to string
js & array to string https://stackoverflow.com/questions/13272406/convert-string-with-commas-to- ...
- From Ruby array to JS array in Rails- 'quote'?
From Ruby array to JS array in Rails- 'quote'? <%= raw @location_list.as_json %>
- 解决js array的key不为数字时获取长度的问题
最近写js时碰到了当数组key不为数字时,获取数组的长度为0 的情况. 1.问题场景 var arr = new Array(); arr[‘s1‘] = 1001; console.log(arr. ...
- JS Array.reverse 将数组元素颠倒顺序
<pre><script type="text/javascript"> //JS Array.reverse 将数组元素颠倒顺序//在JavaScript ...
- js Array 中的 map, filter 和 reduce
原文中部分源码来源于:JS Array.reduce 实现 Array.map 和 Array.filter Array 中的高阶函数 ---- map, filter, reduce map() - ...
- js array & unshift === push head
js array & unshift === push head const arr = [1, 2, 3]; console.log(arr.unshift(4, 5)); // 5 con ...
- js Array.from & Array.of All In One
js Array.from & Array.of All In One 数组生成器 Array.from The Array.from() static method creates a ne ...
随机推荐
- 详解SpringMVC
详解SpringMVC 一.什么是MVC? MVC是模型(Model).视图(View).控制器(Controller)的简写,是一种软件设计规范.就是将业务逻辑.数据.显示分离的方法来组织代码. ...
- Mybatis总结(一)
Mybatis总结(一) 一.Mybatis启动流程(代码层面) 关于config.xml <?xml version="1.0" encoding="UTF-8& ...
- charles配置
https://www.cnblogs.com/ceshijiagoushi/p/6812493.html https://www.zzzmode.com/mytools/charles/
- https://learnku.com/docs/go-blog/qihoo/6532 。 heap size went up to 69G, with maximum garbage collection (GC)
https://learnku.com/docs/go-blog/qihoo/6532 Use a Task Pool, a mechanism with a group of long-lived ...
- new() 和 make() 的区别 var arr1 = new([5]int) var arr2 [5]int
Effective Go - The Go Programming Language https://golang.org/doc/effective_go.html#allocation_new A ...
- js部分知识整理,google浏览器的代码调试
整理一些学过的js知识点,包括js中3个括号的含义,this的使用,递归,google浏览器的代码调试.Location的属性及常用方法,window对象常用方法,open方法等. js括号 在js中 ...
- Dos命令思维导图
通过思维导图的方式,总结常用Dos命令. 各种思维导图下载地址
- Sublime text之中文乱码超简单解决方案
很多玩程序的小伙伴,刚开始使用Sublime Text神器软件时,都会遇到打开一个程序文件,里面的中文编程乱码,不知道怎么办,网上也有很多不同解决方案,这里小编跟大家分享一个超简单的办法. 打开文档后 ...
- DFS——求图的连通性问题
DFS作为一个竞赛必学的一个知识点,怎么说我都得写一下 遍历就相当于爆搜,只不过是搜的方式比较规整罢了. 深度优先遍历:为了避免重复访问某个顶点,可以设一个标志数组vis[i],未访问时值为0,访问一 ...
- Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest(贪心)
题目链接:https://codeforces.com/contest/1265/problem/C 题意 从大到小给出 $n$ 只队伍的过题数,要颁发 $g$ 枚金牌,$s$ 枚银牌,$b$ 枚铜牌 ...