当前位置:网站首页>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);
边栏推荐
- POJ1611_ The Suspects
- Enjoy the luxury meta universe louis:the game, and participate in the NFT series digital collection white roll activity | tutorial
- Simple blockchain day based on bolt database (2)
- Plus版SBOM:流水线物料清单PBOM
- Detailed explanation of flask framework
- CEPH distributed storage performance tuning (6)
- Fundamentals of mathematics 02 - sequence limit
- QT | qcheckbox of control
- 浪潮之巅——读书笔记+摘录+感悟
- Solution: the idea project does not display a tree view
猜你喜欢
随机推荐
Data Lake (20): Flink is compatible with iceberg, which is currently insufficient, and iceberg is compared with Hudi
Solution: the idea project does not display a tree view
Vi. analysis of makefile.build
2022 global Vocational Education Industry Development Report
(07) flask is OK if you have a hand -- flask Sqlalchemy
Watermelon book chapter 3 (first & second)
An overview of kernel compilation system
Example of MATLAB dichotomy (example of finding zero point by dichotomy)
Detailed explanation of flask framework
Bishi journey
Detailed explanation of flask framework
V. introduction of other objectives and general options
Laboratory procedures and references of chloramphenicol acetate
Watermelon Book + pumpkin book chapter 1-2
Transactions in MySQL
Redistemplate cannot get the value according to the key
Redis data type
Self built personalized automatic quotation system to cope with changeable quotation mode
Uniapp video video playback is not completed. It is forbidden to drag the progress bar fast forward
I/o instance operation







