当前位置:网站首页>JS true / false array conversion
JS true / false array conversion
2022-07-27 12:38:00 【ray_ zzzzz】
True and false array conversion
<body>
<div>a</div>
<div>a</div>
<div>a</div>
<script>
// Turn a pseudo array into an array
let a = document.querySelectorAll('div'); // This is the pseudo array provided by the system
let arr1 = [].slice.call(a);
console.log(arr1)
// Convert a true array into a pseudo array
let obj = {
};
let arr2 = [1,2,3];
[].push.apply(obj,arr2)
// console.log(obj)
</script>
</body>
in addition , There is another way to convert pseudo array to real array , But in IE8 And below will report errors , Therefore, the above method is recommended
// This method can also convert pseudo array to true array , But in IE8 And below will report errors
var arr = [];
var obj = {
0:'ldt',
1:18,
2:' Woman ',
length:3
};
[].push.apply(arr,obj);
// console.log(arr);

But this method is used in IE8 And the following can turn the pseudo array of the system into an array
var a = document.querySelectorAll('div');
var arr = [];
[].push.apply(arr,a);
console.log(arr);
边栏推荐
- Log4j2.xml configuration details
- The strongest distributed locking tool: redisson
- 概述有名内部类与匿名内部类
- 浪潮之巅——读书笔记+摘录+感悟
- ArrayList常用方法总结
- Advance in the flutter project_ image_ Picker component usage
- Does the service layer need an interface
- Implicit indicators for evaluating the advantages and disadvantages of automated testing
- Chapter 10 enumeration classes and annotations
- POJ1611_ The Suspects
猜你喜欢

20210518-Cuda

Shutter project scrollcontroller attached to multiple scroll views, failed assertion: line 109 POS 12 error handling
![[database data recovery] a data recovery case in which the disk partition where the SQL Server database is located is insufficient and an error is reported](/img/8a/478209854cb5ce139afc338d106d36.png)
[database data recovery] a data recovery case in which the disk partition where the SQL Server database is located is insufficient and an error is reported

Chapter 10 enumeration classes and annotations

Openpyxl drawing area map

虚拟偶像的歌声原来是这样生成的!

V. introduction of other objectives and general options

How to use the server to build our blog

隔离级别

5V升压9V芯片
随机推荐
Xposed+FDex2 app脱壳 (黑猫投诉app脱壳)
20210422 consolidation interval
When the script runs in the background, it redirects the log from the console to its own named file
POJ1611_The Suspects
浪潮之巅——读书笔记+摘录+感悟
Fundamentals of mathematics 02 - sequence limit
Plus SBOM: assembly line BOM pbom
Mixin\ plug in \scoped style
SQL question brushing: find out the current salary of all employees
Will MySQL fail to insert data? Why?
P1876 turn on the light [getting started]
P1321 word overlay restore [getting started]
关于2022年3月9日之后Typora登录不了--已解决
虚拟偶像的歌声原来是这样生成的!
XXL job parameter transfer
How to ask questions on the road for the first time - necessary skills for self-study (with live playback)
20210518-Cuda
[excerpt] [medical image] common DICOM thumbnail interpretation and viewer converter conversion tool
II. Analysis of the execution process of make menuconfig
The sparksubmit. Main () method submits external parameters and remotely submits the standalone cluster task