Question

I am getting the output of an array in the following format:

[ "12", "13", "14", "25", "7" ]

I was wondering if there's a way to change the separator to a pipe (|), and store the whole string in a variable. I would also need to check if each the value is the object in the array has a value different from "null" or "false".

Thank you!!!

Was it helpful?

Solution

You can do:

arr = arr.join("|");

quick demo: http://jsfiddle.net/hUGg5/

To actually do some checking:

arr = arr.filter(function(i) {
    if (i != null || i != false)
        return i;
}).join("|");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top