Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. //nested array
  2. var a=[[1,2,[3]],4];
  3. //flattened result array
  4. var fa=[];
  5. //flatten function
  6. function flatten(v){
  7. for(var i=0;i< v.length;i++){
  8. var o=v[i];
  9. //check if array value is instance of Array if so call flatten - recursive call
  10. if(o instanceof Array){
  11. flatten(o);
  12. }else{
  13. fa.push(o);
  14. }
  15. }
  16. }
  17. flatten(a);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement