Home > Web Front-end > JS Tutorial > How to convert pseudo array to array through js

How to convert pseudo array to array through js

不言
Release: 2018-07-14 17:33:12
Original
3367 people have browsed it

This article mainly introduces how to convert a pseudo array into an array through js. It has a certain reference value. Now I share it with you. Friends in need can refer to it.

Method 1:

Traverse the pseudo array and push the value into an empty array

Method 2: Use the slice method of the array, which returns an array. Use call or apply to point to the pseudo array

var arr = [].slice.call(arguments);或var arr = Array.propotype.slice.call(arguments);
alert(Array.isArray(arr));
Copy after login

Method 3: New method for arrays in ES6 Array.from()

function testArray(){     
var arg = Array.from(arguments);
     arg.push(7);
     console.log(arg);//1,2,3,4,7 }
 testArray(1,2,3,4);
Copy after login

Method 4: You can also use split() to convert a string into an array

var str = '123456';
 console.log(str.split(''));
Copy after login

The above is the entire content of this article , I hope it will be helpful to everyone’s learning. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

How to use JS to find the array difference set

About the usage of js array filter

The above is the detailed content of How to convert pseudo array to array through js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template