Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //nested array
- var a=[[1,2,[3]],4];
- //flattened result array
- var fa=[];
- //flatten function
- function flatten(v){
- for(var i=0;i< v.length;i++){
- var o=v[i];
- //check if array value is instance of Array if so call flatten - recursive call
- if(o instanceof Array){
- flatten(o);
- }else{
- fa.push(o);
- }
- }
- }
- flatten(a);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement