当前位置: 首页 > news >正文

闲鱼怎么做钓鱼网站厦门百度关键词优化

闲鱼怎么做钓鱼网站,厦门百度关键词优化,网站推广软件污,二级建造师报名时间2022年官网第一次听说伪数组这个概念,听到的时候还以为是说CSS的伪类呢,网上一查,这东西原来还是个很常见的家伙。 何为伪数组 伪数组有两个特点: 具有length属性,其他属性(索引)为非负整数但是却不具备…

第一次听说伪数组这个概念,听到的时候还以为是说CSS的伪类呢,网上一查,这东西原来还是个很常见的家伙。

何为伪数组

伪数组有两个特点:

  1. 具有length属性,其他属性(索引)为非负整数
  2. 但是却不具备数组的方法
    也就是看起来像是数组,然而并不是…

举个例子看看

  1. 函数内部的arguments
function testArguments(a, b, c) {console.log(`arguments is array: ${Array.isArray(arguments)}`);console.log(arguments[0]);console.log(arguments[1]);console.log(arguments[2]);
}
testArguments(1,2,3);

test result
2. DOM列表

  1. JQuery选择得出的列表: $(‘div’)
    随意找一个使用jq的网站,例如:https://www.jq22.com/

如何判断真伪数组

  1. 使用instanceof 方法
  2. 使用Array.isArray()方法: 未必准确,见下文, 使用伪数组.__proto__ = Array.prototype;转换后不可用。
  3. 伪数组.constructor === Array; 适用于带constructor的场景
  4. Object.prototype.toString.call(arr) === ‘[object Array]’

尝试一下:

function testArguments(a, b, c) {console.log(`arguments is array: ${Array.isArray(arguments)}`);console.log(`arguments is array: ${arguments instanceof Array}`);console.log(`arguments is object: ${arguments instanceof Object}`);const newArguments = Array.prototype.slice.call(arguments);console.log(`newArguments is array: ${Array.isArray(newArguments)}`);console.log(`newArguments is array: ${newArguments instanceof Array}`);console.log(`newArguments is object: ${newArguments instanceof Object}`);
}testArguments(1,2,3);

如何把伪数组转换成数组

  1. Array.prototype.slice.call(); / Array.prototype.slice.apply();
  2. 原型继承: 伪数组.__proto__ = Array.prototype;arguments 无影响正常使用
  3. ES6中数组的新方法 from()
方法一: Array.prototype.slice.call(); / Array.prototype.slice.apply();
function testArguments(a, b, c) {console.log(`arguments is array: ${Array.isArray(arguments)}`);console.log(arguments[0]);console.log(arguments[1]);console.log(arguments[2]);const newArguments = Array.prototype.slice.call(arguments);console.log(`newArguments is array: ${Array.isArray(newArguments)}`);console.log(newArguments[0]);console.log(newArguments[1]);console.log(newArguments[2]);
}
testArguments(1,2,3);

方法二: 原型继承: 伪数组.__proto__ = Array.prototype;arguments 无影响正常使用
使用该方法进行转换时,Array.isArray()方法不可用来进行判断。

方法三: ES6中数组的新方法 from()

尝试一下:

function testArguments(a, b, c) {console.log(`arguments is array: ${Array.isArray(arguments)}`);console.log(`arguments is array: ${arguments instanceof Array}`);const newArguments = Array.from(arguments);console.log(`newArguments is array: ${Array.isArray(newArguments)}`);console.log(`newArguments is array: ${newArguments instanceof Array}`);
}
testArguments(1,2,3);

总结

  1. 在使用判断是否为数组时,如果无法知道数组是否可能是使用“原型继承”的方法转换得到的,就不要使用Array.isArray()方法判断对象是否为数组的方法。
  2. 在写转换方法时,由于原型继承: 伪数组.__proto__ = Array.prototype;可能存在判断失误,尽量使用Array.prototype.slice.call(); / Array.prototype.slice.apply();如果可以使用ES6,使用Array.from()方法较为简单明了。
http://www.hrbkazy.com/news/21286.html

相关文章:

  • 什么网站可以做期货关键词seo优化
  • 上海免费网站建设模板推荐网红推广
  • 公司网站百度搜索的描述怎么做江门关键词排名工具
  • 外贸出口新三样百度seo在哪里
  • 自考大专报名官网入口seo的搜索排名影响因素有哪些
  • 网站只用css做tab切换黄冈网站推广软件
  • 如何将WORDPRESS主题换成英文seo内部优化方式包括
  • 网络服务提供者知道或者应当知道网络福建企业seo推广
  • 公安网站建设方案书厦门seo网站优化
  • 国外电商网站如何建立bt鹦鹉磁力
  • 福州seo推广优化成都网站优化排名推广
  • wordpress 支付宝重庆seo点击工具
  • 做问卷调查赚钱的网站seo技巧是什么
  • 直播课网站怎样做的查排名的网站
  • 网站建设 课程百度购物平台客服电话
  • 百度网站收录链接提交广东seo网站推广代运营
  • 网站建设指南专业seo站长工具
  • 如何在局域网中做网站百度竞价推广公司
  • 有后台数据的动态网站郑州网站
  • 广西商城网站建设seo流量优化
  • 千助网站建设网站互联网推广
  • 手工制作垃圾桶东莞关键词排名快速优化
  • 有哪些网站做的比较好看什么是友情链接?
  • 关于搜索引擎的搜索技巧seo外链工具
  • 大型网站开发成本网络推广的手段
  • 自己做的网站被封了网站内部seo优化包括
  • 素材下载网站模板开封网站推广
  • 东莞企业推广网站百度竞价排名的优缺点
  • 丰城做网站磁力天堂
  • 义乌义亭招工做网站养猪工作太原网站建设