Cleaning arrays

32 views
Skip to first unread message

Steve Onnis

unread,
Jul 14, 2011, 8:54:46 PM7/14/11
to mootool...@googlegroups.com

Why would this not work?

 

console.log(Array.from((",1,2,3,4").split(",")).clean())

 

The first item is returned as an empty string but i don’t want it there at all...

 

Steve

Paul Saukas

unread,
Jul 14, 2011, 9:02:52 PM7/14/11
to mootool...@googlegroups.com
Because just '' has defind a blank string value. Clen will only remove a NULL or an Undefined value. you will want erase to get the effect you are looking for 

console.log(Array.from((",1,2,3,4,").split(",")).erase(''))

Paul Saukas

unread,
Jul 14, 2011, 9:07:36 PM7/14/11
to mootool...@googlegroups.com
Let me try that again as i forgot a key bit :) Array.from will create the blank string value to fill in for undefined  

the console out put from your code   ["", "1", "2", "3", "4"]. As to why it does that the mootools devs will know better then me. I just know it does it :D

Ryan Florence

unread,
Jul 15, 2011, 12:10:42 AM7/15/11
to mootool...@googlegroups.com
',1,2,3'.split(',') creates an empty string for the first element.

Array.clean only gets rid of null values and '' != null

You'll want to use Array.filter.
Reply all
Reply to author
Forward
0 new messages