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

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/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的更多相关文章

  1. js Array数组的使用

    js Array数组的使用   Array是javascript中的一个事先定义好的对象(也可以称作一个类),可以直接使用 创建Array对象 var array=new Array(): 创建指定元 ...

  2. 从Chrome源码看JS Array的实现

    .aligncenter { clear: both; display: block; margin-left: auto; margin-right: auto } .crayon-line spa ...

  3. js Array 方法总结

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. js & array to string

    js & array to string https://stackoverflow.com/questions/13272406/convert-string-with-commas-to- ...

  5. From Ruby array to JS array in Rails- 'quote'?

    From Ruby array to JS array in Rails- 'quote'? <%= raw @location_list.as_json %>

  6. 解决js array的key不为数字时获取长度的问题

    最近写js时碰到了当数组key不为数字时,获取数组的长度为0 的情况. 1.问题场景 var arr = new Array(); arr[‘s1‘] = 1001; console.log(arr. ...

  7. JS Array.reverse 将数组元素颠倒顺序

    <pre><script type="text/javascript"> //JS Array.reverse 将数组元素颠倒顺序//在JavaScript ...

  8. js Array 中的 map, filter 和 reduce

    原文中部分源码来源于:JS Array.reduce 实现 Array.map 和 Array.filter Array 中的高阶函数 ---- map, filter, reduce map() - ...

  9. js array & unshift === push head

    js array & unshift === push head const arr = [1, 2, 3]; console.log(arr.unshift(4, 5)); // 5 con ...

  10. 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 ...

随机推荐

  1. IE双击打不开解决办法

    方法1 [百度电脑专家]一键修复 建议下载并安装[百度电脑专家],官网:http://zhuanjia.baidu.com .打开[百度电脑专家],在搜索框内输入"IE修复",在搜 ...

  2. centralized collectors 中心化 采集器

    Fluent Bit https://fluentbit.io/ FluentBit is an open source specialized data collector. It provides ...

  3. Redis 雪崩、穿透和击穿

    https://github.com/doocs/advanced-java/blob/master/docs/high-concurrency/redis-caching-avalanche-and ...

  4. 固定学习率梯度下降法的Python实现方案

    应用场景 优化算法经常被使用在各种组合优化问题中.我们可以假定待优化的函数对象\(f(x)\)是一个黑盒,我们可以给这个黑盒输入一些参数\(x_0, x_1, ...\),然后这个黑盒会给我们返回其计 ...

  5. 题解 UVA11694 【Gokigen Naname谜题 Gokigen Naname】

    题目 题解 考场上连暴力都不会打的码农题,深搜是真的难 /kk 前置问题 怎么输出"\" cout<<"\\"; 2.怎么处理不在一个环里,可以考虑 ...

  6. Go - 实现项目内链路追踪

    为什么项目内需要链路追踪?当一个请求中,请求了多个服务单元,如果请求出现了错误或异常,很难去定位是哪个服务出了问题,这时就需要链路追踪. 从图中可以清晰的看出他们之间的调用关系,通过一个例子说明下链路 ...

  7. Java——数据类型

    数据类型分类 基本数据类型: 数值型: 整数类型(byte,short,int,long): 浮点类型(float,double): 字符型(char): 布尔值(boolean): 引用数据类型: ...

  8. 39.NFS(网络文件系统)

    要共享文件的主机都是Linux系统时推荐在客户端部署NFS 服务来共享文件. NFS(网络文件系统)服务可以将远程Linux 系统上的文件共享资源挂载到本地主机的目录上,从而使得本地主机(Linux ...

  9. Java常用类库2

    1.java.util.Date类 package LESSON9; import java.util.Date; public class demo1 { public static void ma ...

  10. 简谈图论重要性&&图论总结

    从外地学习回来,我对图论才有认识(以前就没接触过,非常尴尬),说实话,学好图论的重要性,就像学数学时在进行解析几何时,图极有可能是打开答案的最后秘钥,也就是数形结合,而懂的人永远明白,用图解决绝对比用 ...