当前位置:网站首页>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);
边栏推荐
- When the script runs in the background, it redirects the log from the console to its own named file
- Shutter project scrollcontroller attached to multiple scroll views, failed assertion: line 109 POS 12 error handling
- 数据湖(二十):Flink兼容Iceberg目前不足和Iceberg与Hudi对比
- You haven't connected to the proxy server. There may be a problem or the address is incorrect (how to check the proxy server IP)
- Dominoes staged: the beginning and end of the three arrow capital crash
- Interviewer: how to deal with the data loss of redis master-slave cluster switching?
- Use redis' sorted set to make weekly hot reviews
- Detailed explanation of flask framework
- 12 pictures, take you to thoroughly understand ZGC garbage collector!
- 20210519 leetcode double pointer
猜你喜欢

Error: the source of the existing CacheManager is: urlconfigurationsource

Self built personalized automatic quotation system to cope with changeable quotation mode

Configuration files in MySQL

js真伪数组转换

最强分布式锁工具:Redisson

Top 10 international NFT exchanges

JVM memory model

概述有名内部类与匿名内部类

What are metauniverse and NFT digital collections?

Enjoy the luxury meta universe louis:the game, and participate in the NFT series digital collection white roll activity | tutorial
随机推荐
[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
XXL job parameter transfer
Watermelon Book + pumpkin book chapter 1-2
Bishi journey
Simple blockchain day based on bolt database (2)
Redis data type
Will MySQL fail to insert data? Why?
Dominoes staged: the beginning and end of the three arrow capital crash
How to use the server to build our blog
Detailed explanation of flask framework
开关量输入输出模块DAM-5055
2021-3-23-meituan-regular sequence
关于2022年3月9日之后Typora登录不了--已解决
ArrayList常用方法总结
堆
Openpyxl drawing area map
Detailed explanation of deeplab series (simple and practical annual summary)
Map接口
NFT mall /nft blind box / virtual blind box /nft transaction / customizable second opening
4. Analysis of the execution process of make modules for general purposes