JavaScript :巧用类数组对象生成空数组
来源:互联网 发布:ubuntu 查看磁盘空间 编辑:程序博客网 时间:2024/05/22 15:18
//不使用循环生成 10 个元素都为undefined 的数组var array_like = {length:10};//或者 Array(10) , new Array(10)var a = Array.apply(null,array_like);// 可以理解为: var a = Array (likeArray[0], likeArray[1]......likeArray[9])var b = [].slice.call(array_like);console.log(a);console.log(b);
参考资料:
Syntax
fun.apply(thisArg, [argsArray])
Parameters
thisArg
- The value of
this
provided for the call tofun
. Note that this may not be the actual value seen by the method: if the method is a function in non-strict mode code,null
andundefined
will be replaced with the global object, and primitive values will be boxed. argsArray
- An array-like object, specifying the arguments with which
fun
should be called, ornull
orundefined
if no arguments should be provided to the function. Starting with ECMAScript 5 these arguments can be a generic array-like object instead of an array. See below for browser compatibility information
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply
0 0
- JavaScript :巧用类数组对象生成空数组
- javascript清空数组与clone对象
- 浅谈JavaScript空数组[]和空对象{}的布尔运算
- javascript清空数组
- JavaScript清空数组
- JavaScript 数组 JavaScript 对象
- 怎么清空javascript数组
- 怎么清空javascript数组
- 对象为空&&数组包含
- 【JavaScript】对象结构的简化--删除Json中的空属性、空数组
- JavaScript对象与数组
- JavaScript对象与数组
- javascript 数组Array对象
- JavaScript 对象数组
- javascript 数组Array对象
- JavaScript Array数组对象
- JavaScript的数组对象
- JavaScript 对象和数组
- http协议中get和post方法的优点和缺点
- 2014年4月操作系统份额:Windows XP仍然在26%以上,Linux微涨
- dvi切换器的特点有哪些
- jqplot初识
- 单点登录 sso 免费产品CAS
- JavaScript :巧用类数组对象生成空数组
- STL中map, list, and pair的学习笔记
- Discuz!X2 附件分表与主题图片表解析
- jQuery中ajax的使用和缓存问题解决
- Windows热键注册原理
- Hadoop Yarn NodeManger架构分析
- Cortex寄存器基础
- HQL查询的参数绑定
- 接口应用