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. Ajax中的同源政策

    Ajax中的同源政策 Ajax请求限制 Ajax只能向自己的服务器发送请求.比如现在有一个A网站.有一个B网站,A网站中的HTML文件只能向A网站服务器中发送Ajax请求,B网站中的HTML文件只能向 ...

  2. Linux中LPC、RPC、IPC的区别

    其实这玩意儿就是纸老虎,将英文缩写翻译为中文就明白一半了. IPC:(Inter Process Communication )跨进程通信 这个概念泛指进程之间任何形式的通信行为,是个可以拿来到处套的 ...

  3. 一个cgi的例子

    cgi的详细资料可以参考 http://httpd.apache.org/docs/2.4/howto/cgi.html 下面是一个python实现的cgi脚本,里面体现了一些cgi的用法,使用其他脚 ...

  4. 【Coredump】调试之旅

    测试反馈,core了. 拿到环境,发现6和11,一个是重复释放,一个是非法指针. 用GDB一挂 ,发现 1 GNU gdb (GDB) 7.5 2 Copyright (C) 2012 Free So ...

  5. 系列trick - 随机

    系列trick - 随机 不断更新中,欢迎来提供idea 随机的字符串 出现次数 \(\ge 2\) 的子串期望长度是 \(\log n\) 两个随机串的期望LCP,LCSuf,LCSub长度是 \( ...

  6. Azure Terraform(八)利用Azure DevOps 实现Infra资源和.NET CORE Web 应用程序的持续集成、持续部署

    一,引言 上一篇讲解到利用 Azure DevOps 将整个 Azure Web App,Azure Traffic Manager profile,Azure Storage Account,Azu ...

  7. Flink-v1.12官方网站翻译-P021-State & Fault Tolerance-overview

    状态和容错 在本节中,您将了解Flink为编写有状态程序提供的API.请看一下Stateful Stream Processing来了解有状态流处理背后的概念. 下一步去哪里? Working wit ...

  8. redis分布式锁的这些坑,我怀疑你是假的开发

    摘要:用锁遇到过哪些问题? 一.白话分布式 什么是分布式,用最简单的话来说,就是为了较低单个服务器的压力,将功能分布在不同的机器上面:就比如: 本来一个程序员可以完成一个项目:需求->设计-&g ...

  9. 和我一起理解js中的事件对象

    我们知道在JS中常用的事件有: 页面事件:load: 焦点事件:focus,blur: 鼠标事件:click,mouseout,mouseover,mousemove等: 键盘事件:keydown,k ...

  10. Codeforces Global Round 7 C. Permutation Partitions(组合数学)

    题意: 给你 n 长全排列的一种情况,将其分为 k 份,取每份中的最大值相加,输出和的最大值和有多少种分法等于最大值. 思路: 取前 k 大值,储存下标,每两个 k 大值间有 vi+1 - vi 种分 ...