Created
December 31, 2011 06:11
Remove empty elements from an array in Javascript and join it as string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**This is example works with only jQuery | |
* @usecase, if you have array with empty values (ex: ["I", "", "want", "", "to", "go", "" ]) | |
* but you want to return this array as a string. | |
*/ | |
var myRoom = { | |
myAction: function(array){ | |
garray = $.grep(array,function(n){ | |
return(n); | |
}); | |
//join by ' ' | |
return garray.join(' '); | |
} | |
}; | |
//Out put is "I want to go" |
Author
nuwansh
commented
Dec 31, 2011
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment