Home >Web Front-end >JS Tutorial >How to convert pseudo array to array through js
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));
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);
Method 4: You can also use split() to convert a string into an array
var str = '123456'; console.log(str.split(''));
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!