博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
随题而学(二)多维数组转一维数组
阅读量:7206 次
发布时间:2019-06-29

本文共 1657 字,大约阅读时间需要 5 分钟。

多维数组转一维数组:[1,[2,3]] ==》 [1,2,3]

function tran(array){if(Object.prototype.toString.call(array) != '[object Array]'){alert(Object.prototype.toString.call(array) + "非数组")return ;}var newArr = [];function trans(arr){ for (var num = 0; num < arr.length;num ++){ if(arr[num].length){ trans(arr[num]); } else { newArr.push(arr[num]); } } } trans(array); return newArr; }

 

[javascript] 
 
op = Object.prototype,ostring = op.toString,...function isFunction(it) {return ostring.call(it) === '[object Function]';}function isArray(it) {return ostring.call(it) === '[object Array]'; }

 

Object.prototype.toString  与 typeof 区别:

typeof

[plain]
  1. 在使用 typeof 运算符时采用引用类型存储值会出现一个问题,无论引用的是什么类型的对象,它都返回 "object"。 
ECMA 对Object.prototype.toString的解释( )
[plain] 
  1. Object.prototype.toString ( )  
  2.   
  3. When the toString method is called, the following steps are taken:  
  4.   
  5. If the this value is undefined, return "[object Undefined]".  
  6. If the this value is null, return "[object Null]".  
  7. Let O be the result of calling ToObject passing the this value as the argument.  
  8. Let class be the value of the [[Class]] internal property of O.  
  9. Return the String value that is the result of concatenating the three Strings "[object ", class, and "]".  

 

var oP = Object.prototype,toString = oP.toString;console.log(toString.call([123]));//[object Array]console.log(toString.call('123'));//[object String]console.log(toString.call({a: '123'}));//[object Object]console.log(toString.call(/123/));//[object RegExp]console.log(toString.call(123));//[object Number]console.log(toString.call(undefined));//[object Undefined]console.log(toString.call(null));//[object Null]

参考:,,

转载于:https://www.cnblogs.com/yunkong/p/4399037.html

你可能感兴趣的文章
SharePoint获取UserProfile的信息
查看>>
[题解]第十一届北航程序设计竞赛预赛——I.神奇宝贝大师
查看>>
Python--关于连接符+
查看>>
office 所有后缀对应的 content-type
查看>>
Linux 第十四天
查看>>
第4章 基本TCP套接口编程
查看>>
Android Studio 1.1 使用介绍及导入 jar 包和第三方依赖库
查看>>
Mysql主键、外键和索引的区别
查看>>
struts基础
查看>>
块状链表 codevs 2333弹飞绵羊
查看>>
(九)jsMath
查看>>
CE_现金模组基本概念(概念)
查看>>
饭后一题
查看>>
Zynq-7000 FreeRTOS(一)系统移植配置
查看>>
[笔记][朝花夕拾][Multisim基础电路范例].第一章 RLC电路,第七、八节 米勒定理...
查看>>
免费论文查重
查看>>
【GPRS】GSM和GPRS模块的应用
查看>>
第一章 Docker简介和基本概念
查看>>
java代码-----实现打印三角形
查看>>
python(4) 小程序-异步加载
查看>>